1. 程式人生 > >ios 最簡單解決UIScrollView不響應TouchesBegin

ios 最簡單解決UIScrollView不響應TouchesBegin

1:@property MyScrollView *scrollView;

2:給MyScrollView,增加類別:MyScrollView+Touch

3:在類別裡實現下面三個方法:

@implementation MyScrollView (Touch)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
}
-(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

4:- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self hiddenkeyBoard];

}

上面的方法未免較繁瑣,所以花了20分鐘思考比較簡單的方法,實現相似的效果。

我的超級簡單方法:

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
if (self.msgTF.isFirstResponder == YES) {
[self.view endEditing:YES];
}
}