0

我正在尝试放大和缩小 imageView

这是代码

- (void)pinch:(UIPinchGestureRecognizer *)gesture
{
   if (handSelected == YES)
   {
    if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateChanged)
    {
        NSLog(@"gesture.scale = %f", gesture.scale);

        CGFloat currentScale = self.imgHand.frame.size.width / self.imgHand.bounds.size.width;
        CGFloat newScale = currentScale * gesture.scale;

        if (newScale < 1.0) {
            newScale = 1.0;
        }
        if (newScale > 4.0) {
            newScale = 4.0;
        }

        CGAffineTransform transform = CGAffineTransformMakeScale(newScale, newScale);
        self.imgHand.transform = transform;
        gesture.scale = 1;
    }
   }
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self adjustRingPressed:self];
    self.view.multipleTouchEnabled = YES;
    self.imgHand.multipleTouchEnabled = YES;
    UIPinchGestureRecognizer *gst = [[UIPinchGestureRecognizer alloc] initWithTarget:self.imgHand action:@selector(pinch:)];
    [gst setDelegate:self];
    [self.imgHand addGestureRecognizer:gst];

}

看来我的捏代码永远不会运行

4

2 回答 2

2

尝试添加:

self.imgHand.userInteractionEnabled = TRUE;

默认情况下 UIImageView 有 userInteractionEnabled = FALSE

于 2013-03-25T14:00:08.807 回答
0

使其成为gesture以下模板代码的功能:

- (IBAction)handlePinch:(UIPinchGestureRecognizer *)recognizer
{
    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1;
}
于 2013-03-25T13:34:59.040 回答