when scrolling horizontally in a UIScrollview, if I quickly swipe twice in the same direction the scroll view jumps violently. Is there anyway to prevent this from happening? To explain in detail, here's an event log from the scrollview where in most delegate methods I just print the x coordinate.
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
The most notable thing in the log is right after scrollViewWillBeginDeceleration when the contentoffset.x jumps with ~6000 points in a matter of milliseconds.
Implementation
The uiscrollview and uiscrollviewdelegate are in the same class, a subclass of uiscrollview which also implements the uiscrollviewdelegate protocol, nothing special is done to contentoffset, and the only properties set on the scrollview are:
self.showsHorizontalScrollIndicator = YES;
self.scrollsToTop = NO;
self.delegate = self;
The scrollview subviews are added once from a viewwillappear call in a uiviewcontroller which hosts the uiscrollview (and the contentSize is set appropriately). Scrolling, waiting a little while, and scrolling again works perfectly.
Please set the scroll view in your required direction and as well as co-ordinate for which you want the scroll and use the proper connection to XIB then it will work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With