我有一个带导航栏的 View
实际上我已经获取了一个 Image View 并将其放在导航栏上......
因为我想要按钮不在右边或左边而是在导航栏的某个地方
通过这种方法我可以识别 View 上的触摸但无法识别导航栏上的触摸?
我能改变什么吗... 在这个方法中... 为什么?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {
CGPoint p;
p.x=0;
p.y=0;
p = [[touches anyObject] locationInView:self.nvbrCalculateBar];
NSLog(@" %f",p.x);
if(p.x==0 && q.x==0)
{
}
else
{
//加载 View
}
}
最佳答案
您可以将 UITapGestureRecognizer 添加到您的 UIImageView,这应该可以解决问题
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEvent:)];
[yourImageView addGestureRecognizer:tap];
[tap release];
- (void)tapEvent:(UITapGestureRecognizer *)gesture {
//Do whatever you need when user taps the imageView
}
同时将 imageView 的 userInteractionEnabled 设置为 YES,以便能够接收手势识别器事件。
希望这对您有所帮助。
关于iphone - 无法识别触摸导航栏的 ImageView 。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7361625/