UIPinchGestureRecognizer 没有响应
我有一个通用二进制应用程序,目前正在开发该应用程序的 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");
}
我确信我错过了一些愚蠢的事情。我以前用过这个东西,但我一生都无法弄清楚出了什么问题。
I have a universal binary application and currently working on the iPad version of the application. The iPad is using a uitabbarcontroller and on the second tab I have 6 images and when adding a UIPinchGesture it is not responding. I have userInteractionEnabled=YES;
I tried adding the image view programmatically and then adding the gesture recognizer and still nothing seems to work.
I tried setting the delegate to the view controller and implementing one of the delegate methods and didn't get any responses. Below is the code sample of what I am doing:
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");
}
I'm sure it's something silly that I'm missing. I've used this stuff before but can't for the life of me figure out what is going wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
userInteractionEnabled
设置为YES
。默认为NO
。此外,为了处理多点触摸(即捏合操作),需要将multipleTouchEnabled
设置为YES
。Set
userInteractionEnabled
toYES
. The default isNO
. Also, in order to handle multi-touches, which is what the pinch is,multipleTouchEnabled
needs to be set toYES
.您将其放入什么视图?
是滚动视图吗?
另外
img2.multipleTouchEnabled = YES
,默认情况下不启用多点触控,捏合需要多个手指。(
img2Pinch
已正确释放)What view are you placing it into?
Is it a scroll view?
Also
img2.multipleTouchEnabled = YES
, multi touch is not enabled by default, a pinch requires multiple fingers.(
img2Pinch
is correctly released)