How to disable scroll in a specific subview of a UIScrollView
ios, objective-c, uipangesturerecognizer, uiscrollview
Solution
Thanks to Dev and Astoria, I have solved this problem. Now I want post my solution here in case there will be someone who meet the same problem as mine.
Here is the result:
Because the Horizontal Only View is not a scrollView (actually it's a JBLineChartView), the easiest scrollViewDidScroll way doesn't help.
We still need GestureRecognizer to achieve this goal, but in a more basic way, just as Dev said, -touchesBegan methods. Sadly UIScrollView will not respond to this kind of touch, we need write a category for it, as code below:
@implementation UIScrollView (UITouchEvent)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
self.scrollEnabled = YES;//This is the only line that you need to customize
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesMoved:touches withEvent:event];
[super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
}
@end
Ha, then it works!
BTW....This is my first question on StackOverflow, and it's a really nice tour.
Problem
I have a `UIScrollView` which contains many subviews. One of the subview is designed to show a linechart, so the user may need to drag horizontally. The truth is when I mean to drag my finger horizontally, the vertical scroll of the `UIScrollView` is easily activated. Now I want to disable the vertical scroll in the subview of chart, and leave it active in the rest parts. I've tried to add a `UIPanGestureRecognizer` to my chart subview. It did disabled the vertical scroll but the horizontal scroll is disabled too. I know I can write codes in the handler of the gesture recognizer to tell vertical or horizontal scroll i needed. But the horizontal scroll is actually managed by the subview's controller, which is a third-party library (`JBChartView` to be specific). I want to know whether there is a simple way to solve this problem. Many thanks.