Iphone UITapgestureRecognitor莫名其妙地停止识别点击手势

Iphone UITapgestureRecognitor莫名其妙地停止识别点击手势,iphone,objective-c,ios7,uitapgesturerecognizer,Iphone,Objective C,Ios7,Uitapgesturerecognizer,简单地说,我分配给UIImageView的uiTapGestureRecognitizer将不可避免地、莫名其妙地停止触发它所指向的方法 更奇怪的是,有时它只需轻敲一下就无法识别这个手势,而有时则需要几十下几十下的轻敲。然而,每次都会不可避免地停止 我尝试将轻触手势设置为强关联属性,但没有效果 我最近尝试的(没有成功)是,在手势的选择器方法运行它的过程之后,我删除了手势,然后重新分配并初始化了一个新的UITapGestureRecognitizer,但没有效果。这让我相信问题出在UIImageV

简单地说,我分配给
UIImageView
uiTapGestureRecognitizer
将不可避免地、莫名其妙地停止触发它所指向的方法

更奇怪的是,有时它只需轻敲一下就无法识别这个手势,而有时则需要几十下几十下的轻敲。然而,每次都会不可避免地停止

我尝试将轻触手势设置为强关联属性,但没有效果

我最近尝试的(没有成功)是,在手势的选择器方法运行它的过程之后,我删除了手势,然后重新分配并初始化了一个新的
UITapGestureRecognitizer
,但没有效果。这让我相信问题出在
UIImageView
上,而不是
uiTapGuestureRecognitizer
——但尽管如此,我还是不知道

但是,我正在将
UIImageView
放进一些
UIView
动画中,所以这可能与此有关

另外,
UIImageView
启用了用户交互,我从未禁用过它

有什么建议吗?如果有帮助的话,我很乐意发布代码。下面是一些代码:

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

动画:

[UIView animateWithDuration:0.2
                          delay:0.0         
                        options:UIViewAnimationOptionAllowUserInteraction
                     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];
                             }];  
上面的代码已更改
animateWithDuration:completion:
方法和
transitionWithView:duration:options:animations:completion:
方法。 这里的重要关键字是
UIViewAnimationOptionAllowUserInteraction
。这将允许用户在图像设置动画时进行交互


如果点击手势在一段时间后仍然无法识别,请向我显示
tapImageView
方法的代码。

使用
UIViewAnimationOptionAllowUserInteraction
将SubviewToFront

[view addSubview:self.cardImageView];
[view bringSubviewToFront:self.cardImageView];
动画:

[UIView animateWithDuration:0.2
                          delay:0.0         
                        options:UIViewAnimationOptionAllowUserInteraction
                     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];
                             }];  

如果您正在将imageview添加到uiscrollview,那么我担心大多数情况下手势识别器都无法工作。或者您尝试在父视图上启用用户交互。

可能是因为您添加了“少数UIView动画”的子视图,所以每次您都必须对所有UIView进行用户交互=是;如果您可以与我们共享一些代码,例如手势识别器的分配、它对imageView的分配以及
UIViewAnimation
块,这将非常有用。您的UIImageView是否将手势识别器添加到属性中?因为它应该是。@JohnWoods是的,我已经发布了代码above@n00bProgrammer张贴。还有什么吗?imageview是在-(void)loadView{}的方法重写中添加到scrollview的。你可能认为它仍然需要你的解决方案吗?有什么可以尝试吗?很好,阿努布拉塔。我会尝试一下,然后再给你回复对不起…我会尝试找到一种新的方法,你可能已经解决了它!这个问题一直折磨着我。谢谢-再多做一点测试,如果它坚如磐石,赏金就是你的照片,它再次发生了。你能在GitHub上上传你的项目的简化版本吗?你在哪里做
gesturerenconliner.enable=NO
吗?我不想上传这个项目,但为了回答你的问题,我没有这样做。我可以修改这个问题以显示更多代码,不过@Warif Akhand Rishiit可能会奖励你,因为这个问题不是热门话题。在我解决这个问题时,你介意继续支持我吗?
[view addSubview:self.cardImageView];
[view bringSubviewToFront:self.cardImageView];
[UIView animateWithDuration:0.2
                          delay:0.0         
                        options:UIViewAnimationOptionAllowUserInteraction
                     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];
                             }];