UIPinchGestureRecognizer和UIRotationGestureRecognizer无法正常工作

时间:2015-06-06 03:48:09

标签: ios objective-c uiimageview uigesturerecognizer uipinchgesturerecognizer

嘿伙计我正试图让用户旋转并缩放我以编程方式添加的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;
}

任何人都知道什么是错的,为什么我的手势不起作用?

1 个答案:

答案 0 :(得分:0)

UIImageView太小,无法在模拟器上正确捏合和旋转。