Erik
Erik

Reputation: 12140

Disable taps on UIScrollView

I would like to disable the effect of the UIScrollView, that it cancels the current setContentOffset animation when tapped. However, panning should still be recognized at any time.

The reason is that I have implemented custom page-sizes (By using the UIScollView delegate's method - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset, where I set targetContentOffset, such that it is a valid page bound).

If a user now taps while an animation is going on, the UIScrollView cancels the animation, which I want to avoid, because it leaves the UIScrollView with an invalid contentOffset.

Upvotes: 1

Views: 804

Answers (1)

Andy Riordan
Andy Riordan

Reputation: 1154

There's a UIScrollViewDelegate method, scrollViewDidEndScrollingAnimation:, which tells you when a scroll view animation caused by calling setContentOffset:animated: completes. I ended up setting scrollEnabled to NO on the scroll view before I call setContentOffset:animated, then setting it back to YES in scrollViewDidEndScrollingAnimation:. Effectively the user can't tap to cancel the scroll animation.

Upvotes: 1

Related Questions