[10秒学会] - iOS手势缩放View

    UIImageView *showImgView = [[UIImageView alloc]initWithFrame:CGRectMake(100,200,200,200)];
    showImgView.image =[UIImage imageNamed:@"30"];
    showImgView.contentMode =UIViewContentModeScaleAspectFit;
    [showImgView setUserInteractionEnabled:YES]; //是图片 需要开启
    [showImgView setMultipleTouchEnabled:YES];
    [self addGestureRecognizerToView:showImgView];
    [self.view addSubview:showImgView];
    
  
- (void) addGestureRecognizerToView:(UIView *)view {
    UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchView:)];
    [view addGestureRecognizer:pinchGestureRecognizer];
}
    
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer {
    UIView *view = pinchGestureRecognizer.view;
    if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
        view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
        pinchGestureRecognizer.scale = 1;
    }
}


你可能感兴趣的:(iOS手势缩放View)