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 は適切に設定されます)。スクロールして、少し待ってから、もう一度スクロールすると完全に機能します。