UIPinchGestureRecognizer 没有响应

发布于 2024-11-12 18:02:16 字数 852 浏览 3 评论 0原文

我有一个通用二进制应用程序,目前正在开发该应用程序的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯狂的代价 2024-11-19 18:02:16

userInteractionEnabled 设置为 YES。默认为NO。此外,为了处理多点触摸(即捏合操作),需要将 multipleTouchEnabled 设置为 YES

Set userInteractionEnabled to YES. The default is NO. Also, in order to handle multi-touches, which is what the pinch is, multipleTouchEnabled needs to be set to YES.

悲喜皆因你 2024-11-19 18:02:16

您将其放入什么视图?
是滚动视图吗?

另外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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文