嘿伙计我正试图让用户旋转并缩放我以编程方式添加的UIImageView
的大小但由于某种原因我的手势识别器无效。要添加UIImageView
我使用我通过故事板设置的UITapGesture工作正常。这是我的代码:
-(IBAction)addUIImageView:(UITapGestureRecognizer *)sender {
CGPoint tapLocation = [sender locationInView:_Image];
NSLog(@"Screen tapped");
UIImageView *ImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Image1.png"]];
[ImageView setCenter:[sender locationInView:_Image]];
ImageView.userInteractionEnabled = YES;
ImageView.multipleTouchEnabled = YES;
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(resizeImage:)];
[ImageView addGestureRecognizer:pinchGesture];
UIRotationGestureRecognizer *rotateGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];
[ImageView addGestureRecognizer:rotateGesture];
[self.Image addSubview:ImageView];
}
然后对于我的捏和旋转手势:
- (void)resizeImage:(UIPinchGestureRecognizer *)recognizer {
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
}
和
-(void)rotateImage:(UIRotationGestureRecognizer *)recognizer {
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
recognizer.rotation = 0;
}
任何人都知道什么是错的,为什么我的手势不起作用?
答案 0 :(得分:0)
UIImageView太小,无法在模拟器上正确捏合和旋转。