我需要从 UIScrollView 获取触摸位置。但是当我为我的滚动视图创建一个子类时:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray *touchesArray = [touches allObjects];
UITouch *touch = (UITouch *)[touchesArray objectAtIndex:0];
CGPoint point = [touch locationInView:self];
self.position = point;}
该函数touchesBegan
并不总是被调用。如果我快速滑动,touchesBegan
则永远不会调用,而是scrollViewDidScroll
直接调用。
我无法使用UIGesture (UITapGestureRecognizer, ... )
,因为用户不会点击或滑动。
还有其他方法可以从 UIScrollView 获取位置吗?
编辑 :
谢谢ThXou:https ://stackoverflow.com/a/15763450/1752843
UIScrollView 子类:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
self.position = point;
return self;
}