我有一个UIButton
内部的视图,如下所示:snapshot 01 http://imageshack.us/a/img827/7240/screenshot20130220at333.png
按钮绑定到IBAction
:
-(IBAction)deleteButtonPressed :(id)sender{
NSLog(@"DeleteButtonPressed");
}
我还有另一个视图,显示最后一个视图的集合:snapshot 02 http://img836.imageshack.us/img836/2104/screenshot20130220at339.png
在这个观点的控制器中,我有一点:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[preview addGestureRecognizer:tapGesture];
而且:
- (void)tapAction:(UIGestureRecognizer *)gestureRecognizer{
EditorViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"EditorViewController"];
vc.narration = preview.narration;
self.navigationItem.backBarButtonItem.style = UIBarButtonItemStylePlain;
self.navigationItem.backBarButtonItem.title = @"Done";
vc.navigationItem.backBarButtonItem.style = UIBarButtonItemStylePlain;
vc.navigationItem.backBarButtonItem.title = @"Done";
[self.navigationController pushViewController:vc animated:YES];
}
因此,当我触摸预览时,我会加载另一个视图。当我点击按钮时出现问题。在这种情况下,函数-(IBAction)deleteButtonPressed: (id)sender
不会执行,tapAction
会执行。此外,按下时按钮也会改变。我试图不添加GestureRecognizer然后执行-(IBAction)deleteButtonPressed :(id)sender
。
我做错了什么?当点击按钮时,如何实现这一点,下方的视图无法捕获手势?
答案 0 :(得分:3)
您需要实现shouldReceiveTouch
方法(这是UIGestureRecognizerDelegate
协议的一部分)。
有关您的问题的更多信息: