gpt4 book ai didi

iphone - UITapGestureRecognizer 莫名其妙地停止识别点击手势

转载 作者:太空狗 更新时间:2023-10-30 03:38:30 26 4
gpt4 key购买 nike

尽可能简单地说,我已分配给 UIImageViewUITapGestureRecognizer 将不可避免地莫名其妙地停止触发它指向的方法。

它甚至更奇怪,因为有时它仅在轻按一次后就不再识别手势,而其他时候则需要数十次。但是,每次都没有失败,它不可避免地会停止。

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

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

但是,我将 UIImageView 放入几个 UIView 动画中,所以也许这有什么作用?

此外,UIImageView 启用了用户交互,我从未禁用它。

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

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

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];

动画:

[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];
}];

最佳答案

[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];
}];

以上代码已将 animateWithDuration:completion: 方法更改为 transitionWithView:duration:options:animations:completion: 方法。这里重要的关键字是 UIViewAnimationOptionAllowUserInteraction。这将允许在图像动画时进行用户交互。

如果一段时间后 TapGesture 仍然停止识别,请告诉我你的 tapImageView 方法的代码。

关于iphone - UITapGestureRecognizer 莫名其妙地停止识别点击手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20988155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com