2

我有这样的UIButton内部视图:快照 01 http://imageshack.us/a/img827/7240/screenshot20130220at333.png

该按钮绑定到IBAction

-(IBAction)deleteButtonPressed :(id)sender{
    NSLog(@"DeleteButtonPressed");
}

我还有另一个视图显示了最后一个视图的集合:快照 02

在这个视图的控制器中,在某些时候我有这个:

    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被执行。

我做错了什么?当点击按钮时,如何实现这一点,下面的视图不会捕获手势?

4

1 回答 1

3

您需要实现该shouldReceiveTouch方法(这是UIGestureRecognizerDelegate协议的一部分)。

有关您的问题的更多信息:

手势识别器和按钮操作

于 2013-02-20T16:22:14.817 回答