hitTest 中的 TouchesForView
我有一个像容器一样使用的简单 UIView。 如果我写这段代码:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
NSSet *sTouches = [event touchesForView:self];
NSLog(@"Touches %d", [sTouches count] );
return self;
}
不起作用!我想在 TouchBegan() 之前在 hitTest() 消息中获取触摸计数! 是否可以?
我有这样的层次结构:
UIView
+---> UIScrollView
当触摸我的 UIView
(单击)时,容器会移动。当我在 UIView
上双击(两根手指)时,子 UIScrollView
不适用于 Zoom(例如)。 于是我就想到要抓摸数。
如果触摸次数等于 1,UIView
容器上的 hitTest
将返回“self”。 否则,如果触摸次数大于 1 ( == 2),则 hitTest
返回“scrollview”指针。
换句话说,我想将两个手指事件捕获到 hitTest() 消息/事件中。
I have a simple UIView used like container.
If I write this code:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
NSSet *sTouches = [event touchesForView:self];
NSLog(@"Touches %d", [sTouches count] );
return self;
}
Doesn't work! I would like get touches count in hitTest() message, before touchesBegan()!
Is it possible?
I have this hierarchy:
UIView
+---> UIScrollView
When touch on my UIView
(single tap) the container moves. When I double touch (two finger) on my UIView
, the child UIScrollView
doesn't work for Zoom (for example).
So I have think to catch touches number.
If touch number is equal to one, hitTest
on my UIView
container return "self".
Else, if touch number is great to one ( == 2), hitTest
return "scrollview" pointer.
In others words, I would like catch two finger event into hitTest() message/event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
框架使用
hitTest
来确定哪个视图被点击,从而确定向哪个视图发送touchesBegan
/touchesMoved
/touchesEnded
/touchesCancelled
消息。在调用hitTest
时,您无法判断。也许您可以解释一下您想要实现的目标,因为这似乎不是正确的方法。
hitTest
is used by the framework to determine which view is being hit, and thus which view to send thetouchesBegan
/touchesMoved
/touchesEnded
/touchesCancelled
messages to. At the pointhitTest
is called, you can't tell.Maybe you could explain what you are trying to accomplish, because this doesn't seem like the right way to do it.