UIPinchGestureRecognizer不响应

3
我有一个通用二进制应用程序,目前正在开发iPad版本的应用程序。iPad使用uitabbarcontroller,在第二个选项卡上有6张图片,添加UIPinchGesture时没有反应。我已经设置了userInteractionEnabled=YES;。我尝试通过编程方式添加图像视图,然后添加手势识别器,但仍然无法工作。我尝试将委托设置为视图控制器并实现其中一个委托方法,但没有得到任何响应。以下是我所做的代码示例:
UIImageView *img2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img2-large.png"]];
img2.frame = CGRectMake(20, 20, 100, 100);
[img2 setUserInteractionEnabled:YES];
img2.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:img2];    

UIPinchGestureRecognizer *img2Pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(img2Pinch:)];
[img2 addGestureRecognizer:img2Pinch];
[img2Pinch release];


- (void)img2Pinch:(UIPinchGestureRecognizer *)sender {
      NSLog(@"HERE");
}

我相信我错过了一些愚蠢的东西。我以前用过这个东西,但是现在我想不出哪里出了问题。


我解决了自己的问题,显然我不知怎么地在界面构建器中意外关闭了视图的用户交互功能。愚蠢得-1分。 - dbslone
2个回答

12

userInteractionEnabled设置为YES。默认值为NO。同时,为了处理多点触摸(如捏合手势),需要将multipleTouchEnabled设置为YES


无法使其工作,我甚至尝试使用UITapGestureRecognizer。还有其他想法吗?img2.multipleTouchEnabled = YES; img2.userInteractionEnabled = YES; UIPinchGestureRecognizer *img2Pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(img2Pinch:)]; [img2 addGestureRecognizer:img2Pinch]; [img2Pinch release]; - dbslone
尝试将canBecomeFirstResponder设置为YES。 - csano
显然我解决了自己的问题,不知怎么地,我在界面构建器中意外关闭了视图的用户交互功能。愚蠢得-1分。 - dbslone

0
你把它放在哪个视图中呢? 是一个滚动视图吗?
还有 img2.multipleTouchEnabled = YES,默认情况下不启用多点触摸,捏合手势需要多个手指。
img2Pinch 已经正确释放)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接