[英]Detect touch on uiview under the UIButton when button is pressed
我正在使用uiview父视图....过度触摸开始和触摸结束方法...当我在视图中添加UIButton作为子视图并触摸按钮触地事件被检测到并且相关方法被调用...但是没有调用过度骑行的touchbegan方法......
我想要的是当我触摸按钮时,与触地事件相关联的方法和uiview的touchBegan方法都被同时调用... UI按钮没有将触摸传递给它的超级视图即uiview .....? 知道怎么做吗? 谢谢
我不确定如何在两个不同的视图上同时调用两个touchesBegan
事件,但你可能想要覆盖UIView
的hitTest:withEvent:
方法。 这将允许您在UIButton
下方的视图上捕获触摸事件, 然后它到达按钮(hitTests从window
向上工作到最前面的视图)。
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (passToSubviews)
{
return [super hitTest: point withEvent: event];
}
// otherwise stop the subview receiving touches
if ([super hitTest: point withEvent: event])
{
return self;
}
return nil;
}
也许这可以帮助......
编辑:
只是一个猜测,但你可以尝试:
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView* hitSubview = [super hitTest: point withEvent: event];
if (hitSubview)
{
[self doTouchedInStuff];
return hitSubview;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self doTouchedInStuff];
[super touchesBegan:touches withEvent:event];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.