检测UiScrollView上的触摸位置 [英] Detect touch position on UiScrollView
问题描述
我需要从UIScrollView获取触摸位置。但是当我为我的scrollview创建一个子类时:
I need to get the touch position from a UIScrollView. But when I create a subclass for my scrollview :
- (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
会被直接调用。
The function touchesBegan
isn't always called.
If I swipe fast, touchesBegan
is never called, but scrollViewDidScroll
gets directly called instead.
我无法使用 UIGesture(UITapGestureRecognizer,...)
,因为用户不会点按或滑动。
I can't use UIGesture (UITapGestureRecognizer, ... )
because users don't tap or swipe.
是否还有其他方法可以从UIScrollView获得头寸?
Are there others methods to get the position from UIScrollView ?
编辑:
谢谢你: https://stackoverflow.com/a/15763450/1752843
UIScrollView子类:
UIScrollView subclass :
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
self.position = point;
return self;
}
推荐答案
我看到答案,我认为它可以解决您的问题。似乎SDK不再将触摸处理方法传递给UIScrollView子类。所以,您应该执行 hitTest:
将触摸传递给您的子类。
I saw an answer in SO that I think that it can solve you problem. It seems that the SDK doesn't pass the touch handling methods to the UIScrollView subclasses anymore. So, you should to perform a hitTest:
to pass the touches to your subclass.
查看答案了解更多信息。
See the answer for more information.
这篇关于检测UiScrollView上的触摸位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!