【发布时间】:2014-01-08 06:09:21
【问题描述】:
尽可能简单地说,我分配给UIImageView 的UITapGestureRecognizer 将不可避免地莫名其妙地停止触发它所指向的方法。
它甚至更奇怪,因为有时它仅在一次点击后就无法识别手势,而其他时候则需要数十次点击。但是,每次都不会失败,它不可避免地会停止。
我尝试将点击手势设置为强关联属性,但没有效果。
我最近尝试过的(没有成功)是,在手势的选择器方法运行正常后,我删除了手势,然后重新分配并重新初始化了一个新的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 动画”的子视图可能有问题,因此每次您必须对所有 uiview(s)=YES 进行用户操作;
-
如果您能与我们分享一些代码会很有帮助,例如gestureRecogniser 的分配、imageView 的分配以及
UIViewAnimation块。 -
你的 UIImageView 是你添加手势识别器的属性吗?因为它应该是。
-
@JohnWoods 是的,我已经在上面发布了代码
-
@n00bProgrammer 已发布。还有什么?
标签: iphone objective-c ios7 uitapgesturerecognizer