您必须将触摸传递给子视图,这个类别UIScrollView
将完成这项工作:
@implementation UIScrollView (FixedApi)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touch view = %@", [[touch view].class description]);
if ([[[touch view].class description] isEqualToString:@"UITableView"]) {
//You have touched a UITableView
} else if ([[[touch view].class description] isEqualToString:@"UIView"]) {
//You have touched a UIView
} else {
//Ignore the category and return the touch to the UIScrollView.
[self.superview touchesBegan:touches withEvent:event]; // or 1 nextResponder, depends
[super touchesBegan:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ( !self.dragging ) [self.nextResponder.nextResponder touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
}
@end