UITapGestureRecognizer莫名其妙地停止识别轻击手势

ach*_*chi 7 iphone objective-c uitapgesturerecognizer ios7

尽可能简单地说UITapGestureRecognizer,我已经分配给一个UIImageView将不可避免地和莫名其妙地停止发射它所针对的方法.

它甚至更奇怪,因为有时它只会在一次敲击后停止识别手势,而其他时间则需要数十次敲击才能识别.但是,每次都没有失败,它将不可避免地停止.

我已经尝试将轻拍手势设置为强关联属性,但这没有任何效果.

我最近尝试过的(没有成功)是,在手势的选择器方法运行之后,我删除了手势,然后重新分配并重新初始化了一个新的UITapGestureRecognizer,没有任何效果.这让我相信问题就在于UIImageView而不是UITapGuestureRecognizer- 而是说,我不知道.

但是,我正在UIImageView通过几个UIView动画,所以也许有事情可做呢?

此外,UIImageView已启用用户交互,我从不禁用它.

有什么建议?我很乐意发布代码,如果这会有所帮助.这是一些代码:

设置UIImageView(图像视图和点击手势都已成为属性,以便我可以强烈关联它们):

self.cardImageView = [[UIImageView alloc] initWithFrame:frame];
[self.cardImageView setContentMode:UIViewContentModeScaleAspectFill];
[self.cardImageView setClipsToBounds:TRUE];
[self.cardImageView setBackgroundColor:[UIColor nearBlack]];
[self.cardImageView.layer setBorderColor:[[UIColor fiftyGray]CGColor]];
[self.cardImageView.layer setBorderWidth:1.0];
[self.cardImageView setUserInteractionEnabled:TRUE];

self.imageFullScreenTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
[self.cardImageView addGestureRecognizer:self.imageFullScreenTap];

[view addSubview:self.cardImageView];
Run Code Online (Sandbox Code Playgroud)

动画:

[UIView animateWithDuration:0.2 animations:^
     {
         [self.cardImageView setFrame:[self frameForImageView]];

         [page setAlpha:!fullscreenTemplate];
         [saveExitButton setAlpha:!fullscreenTemplate];
         [optionsButton setAlpha:!fullscreenTemplate];

         if(fullscreenTemplate)
         {
             [self.cardImageView.layer setBorderColor:[UIColor clearColor].CGColor];
             [self.view setBackgroundColor:[UIColor blackColor]];
         }
         else
         {
             [self.cardImageView.layer setBorderColor:[UIColor fiftyGray].CGColor];
             [self.view setBackgroundColor:[UIColor clearColor]];
         }
     }
     completion:^(BOOL finished)
     {
         [scroller setScrollEnabled:!fullscreenTemplate];

         if (self.imageFullScreenTap)
         {
             [self.cardImageView removeGestureRecognizer:self.imageFullScreenTap];
             self.imageFullScreenTap = nil;
         }

         self.imageFullScreenTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
         [self.cardImageView addGestureRecognizer:self.imageFullScreenTap];
     }];
Run Code Online (Sandbox Code Playgroud)

War*_*shi 1

[UIView transitionWithView:self.cardImageView
                  duration:0.2f 
                   options:UIViewAnimationOptionAllowUserInteraction |
                        UIViewAnimationOptionLayoutSubviews
                animations:^(void) {
                    [self.cardImageView setFrame:[self frameForImageView]];
                    [page setAlpha:!fullscreenTemplate];
                    [saveExitButton setAlpha:!fullscreenTemplate];
                    [optionsButton setAlpha:!fullscreenTemplate];
                    if(fullscreenTemplate) {
                        [self.cardImageView.layer setBorderColor:[UIColor clearColor].CGColor];
                        [self.view setBackgroundColor:[UIColor blackColor]];
                    } else {
                        [self.cardImageView.layer setBorderColor:[UIColor fiftyGray].CGColor];
                        [self.view setBackgroundColor:[UIColor clearColor]];
                    }
                } completion:^(BOOL finished) {
                    [scroller setScrollEnabled:!fullscreenTemplate];
                }]; 
Run Code Online (Sandbox Code Playgroud)

上面的代码已经animateWithDuration:completion:用method改变了transitionWithView:duration:options:animations:completion:method。这里重要的关键词是UIViewAnimationOptionAllowUserInteraction。这将允许在图像动画时进行用户交互。

如果在一段时间后 TapGesture 仍然停止识别,请向我展示您的方法的代码tapImageView