[英]touchesBegan - iPhone app UIView
I have a touchesBegan:
method which works fine.我有一个
touchesBegan:
方法,效果很好。 However I recently added a UIView (a button) to my UIViewController and now the button isn't registering taps, however my touchesBegan:
method is.但是我最近在我的 UIViewController 中添加了一个 UIView (一个按钮),现在该按钮没有注册水龙头,但是我的
touchesBegan:
方法是。
How can I tell my touchesBegan:
method to avoid the button?如何告诉我的
touchesBegan:
避免按钮的方法?
Here is my current touchesBegan:
method:这是我当前的
touchesBegan:
方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches began");
UITouch *touch = [touches anyObject];
switch ([touch tapCount])
{
case 1:
break;
case 2:
if(something)
[doing something];
break;
default:
break;
}
}
Make sure that the button is in front ( [self.view bringSubviewToFront: myButton]
).确保按钮在前面(
[self.view bringSubviewToFront: myButton]
)。 Then you can ask the touch in which in view it occurred:然后你可以询问发生在哪个视图中的触摸:
if ([touch.view isEqualTo: myButton]) {
NSLog(@"touch was on button");
}
I had the same problem.我有同样的问题。 When I moved my button to the front (in code via UIViewController.bringSubviewToFront) the touchesBegan no longer was fired when I clicked on the button.
当我将按钮移到前面时(在代码中通过 UIViewController.bringSubviewToFront),当我单击按钮时不再触发 touchesBegan。 I'm running Xcode 4.2, in the simulator.
我在模拟器中运行 Xcode 4.2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.