我不知道究竟如何同时调用两个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];
}
来源
2011-08-04 10:19:23
Sam
passToSubview?只是重写这个方法会有所作为? – Tornado
是的,这将允许您定义检测到触摸的位置,但不能同时在2个不同视图上检测触摸 – Sam
全部完成....非常感谢 – Tornado