2011-06-01 120 views
2

我有一个通用的二进制应用程序,目前正在iPad版本的应用程序上工作。 iPad使用的是uitabbarcontroller,第二个选项卡上有6张图片,添加UIPinchGesture时没有响应。我有userInteractionEnabled=YES;我尝试以编程方式添加图像视图,然后添加手势识别器,但仍然没有任何工作。UIPinchGestureRecognizer没有响应

我试着将代理设置到视图控制器并实现其中一个代理方法,但没有得到任何响应。下面是我在做什么的代码示例:

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"); 
} 

我敢肯定,这是愚蠢的东西我失踪。我之前使用过这些东西,但不能为我的生活找出错误的地方。

+0

我解决我自己的问题显然不知何故,我设法不小心把我在界面生成器视图中启用的用户交互。 -1为愚蠢。 – dbslone 2011-06-01 19:37:51

回答

11

设置userInteractionEnabledYES。缺省值是NO。此外,为了处理多点触摸,这是捏合,multipleTouchEnabled需要设置为YES

+0

无法得到这个工作,我甚至尝试过使用UITapGestureRecognizer。任何其他想法? img2.multipleTouchEnabled = YES; img2.userInteractionEnabled = YES; UIPinchGestureRecognizer * img2Pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(img2Pinch :)]; [img2 addGestureRecognizer:img2Pinch]; [img2Pinch release]; – dbslone 2011-06-01 18:45:47

+0

尝试将canBecomeFirstResponder设置为YES。 – csano 2011-06-01 18:53:44

+0

我解决了我自己的问题,显然我设法在接口生成器中意外启用了用户交互功能。 -1为愚蠢 – dbslone 2011-06-01 19:39:33

0

你对此有何看法? 它是一个滚动视图吗?

img2.multipleTouchEnabled = YES,默认情况下不启用多点触摸,捏点需要多个手指。

img2Pinch被正确地释放)