12

UIScrollview で水平方向にスクロールするときに、同じ方向にすばやく 2 回スワイプすると、スクロール ビューが激しくジャンプします。これが起こらないようにする方法はありますか?詳細を説明するために、ほとんどのデリゲート メソッドで x 座標を出力するだけのスクロール ビューのイベント ログを次に示します。

scrollViewWillBeginDragging:
    14:55:12.034 Will begin dragging!
    14:55:12.037 - Position -0.000000
scrollViewWillBeginDeceleration:
    14:55:12.129 Deceleration rate 0.998000
    14:55:12.152 + Position 314.000000
scrollViewWillBeginDragging:
    14:55:12.500 Will begin dragging!
    14:55:12.522 - Position 1211.000000
scrollViewWillBeginDeceleration:
    14:55:12.530 Deceleration rate 0.998000
    14:55:12.533 + Position 1389.000000
scrollViewDidScroll: (printing values < 0 && > 6000 (bounds.size.width)
    14:55:12.595 !!! Position 7819.000000
    14:55:12.628 !!! Position 9643.000000
    14:55:12.658 !!! Position 10213.000000
    14:55:12.688 !!! Position 10121.000000
    14:55:12.716 !!! Position 9930.000000
    ... contentoffset.x drops with around 400 each scrollviewdidscroll call ...
    14:55:13.049 !!! Position 6508.000000
scrollViewDidEndDecelerating:
    14:55:13.753 Will end deceleration
    14:55:13.761 * Position 6144.000000

ログで最も注目に値するのは、scrollViewWillBeginDeceleration の直後で、contentoffset.x が数ミリ秒で最大 6000 ポイントジャンプします。

実装

uiscrollview と uiscrollviewdelegate は同じクラスにあり、uiscrollviewdelegate プロトコルも実装する uiscrollview のサブクラスであり、contentoffset に対して特別なことは何も行われず、scrollview に設定される唯一のプロパティは次のとおりです。

    self.showsHorizontalScrollIndicator = YES;
    self.scrollsToTop = NO;
    self.delegate = self;

scrollview サブビューは、uiscrollview をホストする uiviewcontroller の viewwillappear 呼び出しから一度追加されます (そして contentSize は適切に設定されます)。スクロールして、少し待ってから、もう一度スクロールすると完全に機能します。

4

4 に答える 4

1

スクロール ビューを必要な方向に設定し、スクロールが必要な座標を設定 XIBへの適切な接続を使用すると、正常に動作します。

于 2012-12-27T06:03:41.447 に答える
0

bouncesZoomプロパティをセットアップする必要があるかもしれませんか?

scrollviewobject.bouncesZoom = NO;
于 2011-10-08T11:12:00.647 に答える
0

UIScrollView のスクロールを少し遅くしたい場合は、たとえば、ユーザーがスクロールするときに NSTimer を追加し、次のようなアニメーションでスクローラーの contentOffset を少し戻すことができます。

.h ファイルで宣言します。

UIScrollView *myScrollView;
NSTimer *scrollCheckTimer;
BOOL delayScroll;

.m ファイル:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (delayScroll == YES) {
        [scrollCheckTimer invalidate];
        delayScroll = NO;
        [myScrollView setContentOffset:CGPointMake(myScrollView.contentOffset.x - 40, contentOffset.y) animated:YES];
    }
    delayScroll = YES;
    scrollCheckTimer = [NSTimer scheduledTimerWithTimeInterval:0.9 target:self selector:@selector(removeDelayBecouseOfTime) userInfo:nil repeats:NO];
}

- (void)removeDelayBecouseOfTime { delayScroll = NO; }
于 2012-05-30T04:10:14.440 に答える
0

このように試すことができます

- (void)enableScrollView
{
    scrollView.userInteractionEnabled = YES;
}

- (void)delayScroll:(id)sender
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    //delay userInteraction 0.1 second, prevent second swipe
    [NSThread sleepForTimeInterval:0.1];
    [self performSelectorOnMainThread:@selector(enableScrollView) withObject:nil waitUntilDone:NO];
    [pool release];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    scrollView.userInteractionEnabled = NO;
    [NSThread detachNewThreadSelector:@selector(delayScroll:) toTarget:self withObject:nil];
}
于 2012-02-09T06:54:13.193 に答える