I have a UIScrollView
with another UIScrollView
inside. They both are scrolled horizontally and have pagingEnabled = YES
.
Assume that I started to scroll inner scroll view and reached the most right bound. And if I proceed scrolling in it, then the outer scrollView begins to move. I need to avoid this. Inner view should jump with rubber-band effect, outer should stay at it's place.
Hope it's clear, but here is a sketch:
I've tried to set outerView.scrollEnabled = NO;
like this:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
outerView.scrollEnabled = NO;
}
, and it works exactly how I need, if to scroll just in innerView. OuterView is not scrolled anymore. But I have to set scrollEnabled
back to YES somewhere for the case if I'd want to scroll outerView again.
I've tried to do it here:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
outerView.scrollEnabled = YES;
}
, but than I'm getting the same problem: after reaching the the most right bound of innerView outerView scrolls instead of innerView jumps with rubber-band effect.
Any suggestions how to solve a problem?
Modify your methods by below way:
I have a similar issue. I found the solution, but it works only with
innerScrollView.bounces = NO
.This works well for me:
Remember to adopt the UIScrollViewDelegate in your class declaration and to set the delegate of the innerScrollView to self (do NOT assign the delegate of the outerScrollView)
UPDATE
This solution works always:
-----------------------------------------------------------------------
OLD ANSWER: doesn't work always
Here is how I solved the problem:
As I understand,
self.delaysContentTouches = NO;
makes all events to be delivered immediately, and- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
prevents passing of these events by responder chain.