【问题标题】:UIPinchGestureRecognizer and UIRotationGestureRecognizer not workingUIPinchGestureRecognizer 和 UIRotationGestureRecognizer 不工作
【发布时间】:2015-08-21 02:58:00
【问题描述】:

大家好,我正在尝试让用户旋转和缩放我以编程方式添加的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;
}

有谁知道出了什么问题以及为什么我的手势不起作用?

【问题讨论】:

  • 应该可以吗? pinchGesture 的 NSLog 是什么?如果您在模拟器中进行测试,您的手势是否正确?
  • 我只是将 NSLog 放入捏合并旋转手势以查看它们是否被调用,无论出于何种原因,它们都不是。在模拟器中,我使用 alt/option 按钮来制作手势。感谢您的帮助!
  • 我发现了问题。我使用的 UIImageView 只有 100x100,使用这么小的图像放大模拟器太难了,所以你最终是对的。感谢您的帮助!

标签: ios objective-c uiimageview uigesturerecognizer uipinchgesturerecognizer


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2012-12-03
    • 1970-01-01
    • 2021-12-23
    • 2012-04-02
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    相关资源
    最近更新 更多