简而言之UITapGestureRecognizer
,我分配给UIImageView
遗嘱的a将不可避免地,莫名其妙地停止使用它所针对的方法。
它甚至更陌生,因为有时仅一次轻击一次它就会停止识别手势,而有时则需要数十次轻击。但是,每次都会无休止地终止。
我尝试将点击手势设置为强烈关联的属性,但这没有任何效果。
我最近尝试过的(没有成功)是,在运行手势的选择器方法之后,我删除了该手势,然后重新分配并重新初始化了一个新的手势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];
动画:
[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
。这将在图像动画时允许userInteraction。
如果TapGesture在一段时间后仍然无法识别,请向我显示您的tapImageView
方法代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句