Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal UIScrollView having vertical UIScrollViews inside - how to prevent scrolling of inner scroll views when scrolling outer horizontal view?

couldn't find a solution for that.

I am building an app, with big scroll view, who has paging (Horizontal). Inside this scroll view, there is a grid of UIView's, and an UIScrollview inside each one of them, with vertical scroll view.

Now, the point is, When I'm paging my 'big' scrollview, sometimes the touch get stuck in one of small scrollviews inside the UIViews of the grid.

I don't know how to avoid it - tried trick with hitTest but still couldn't find the answer.

Hope i'm clear...

Thanks for your help.

Edit:

This is the bigger scrollview:

@implementation UIGridScrollView
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    self.pagingEnabled;
    return self;
}
@end

Now, to this UIGridScroll View, I added as a subview this view:

@implementation UINoteView
{
IBOutlet UIScrollView *_innerScrollView; // this scrollview frame is in the size of the all UINoteView
}

- (void)awakeFromNib
{
    _innerScrollView.contentSize = CGSizeMake(_innerScrollView.frame.size.width, _innerScrollView.frame.size.height+50.0f);
}
@end

The paging works well, the inner scroll view works well, but too many times when I paging the bigger note view, my finger 'get stuck' in the _innerScrollView.

Thanks!

like image 595
Avi Tsadok Avatar asked Nov 07 '12 15:11

Avi Tsadok


1 Answers

@stanislaw, I've just tried the solution you suggest on an iPhone device.

I see your problem.

Your code does prevent occasional scrolls of vertical views but I believe it is not the simultaneous gesture recognition does the job - comment the entire code you provide for inner views and use the code for the outer scroll view with the following modification:

@interface OuterHorizontalScrollView : UIScrollView ...
@property (weak) InnerVerticalScrollView *currentActiveView; // Current inner vertical scroll view displayed.
@end

@implementation OuterHorizontalScrollView
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (self.currentActiveView.dragging == NO) {
        self.currentActiveView.scrollEnabled = NO; // The presence of this line does the job
    }
    return YES;
}

- (void)scrollViewDidEndDragging:(PlacesScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    self.currentActiveView.scrollEnabled = YES; // This is very likely should be done for all subviews, not only a current.
}    
@end
like image 91
burik Avatar answered Oct 18 '22 19:10

burik