Quote:
Originally Posted by sbudhram
So, a little more info, but no solution.
First, I tried subclassing the scroll view to access the touchesBegan/touchesEnded/touchesMoved methods, and just using NSLogs to make sure they were being called. Which they were! I could see that dragging/pressing was triggering the methods for my subclass.
However, if I pressed on something within my scrollview like a button, these methods were NOT called (including my picker). I'm guessing this is because they implement their own touch methods that get precedence over the scrollView. So, next I tried to subclass the picker and use the touchesBegan/Ended methods. No luck, they are not being called. And on top of that, dragging in the picker still triggers the scrollView, though it doesn't trigger the scrollView's touchesBegan/Ended methods that I implemented.
Still looking for a solution. If there are any event handling gurus out there, please speak out!
Thanks.
|
Firstly I am definitely no guru, but I got this to work by creating a UIScrollView subclass and overriding the following methods
HTML Code:
@interface PickerAwareUIScrollView : UIScrollView {
}
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view;
- (BOOL)touchesShouldCancelInContentView:(UIView *)view;
implementation
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
if ([view isKindOfClass:[UIPickerView class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
//|| [view isKindOfClass:[UIPicker class]]
return YES;
}
return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view {
if ([view isKindOfClass:[UIPickerView class]] || [@"UIPickerTable" isEqualToString:[[view class] description]] ) {
return NO;
}
return [super touchesShouldCancelInContentView:view];
}
This cancels the touch handling in the scrollView when the event is inside the UIPickerView.