我想通過PinchGestureRecognizer
進行縮放功能。 我可以通過此代碼進行縮放,但只要我捏出來,imageView就會恢復。 我想做的功能是,如果我有時縮放imageView,它不會每次都恢復。 而代碼scrollView.minimumZoomScale = 3.0
,scrollView.maximumZoomScale = 6.0
不起作用。我應該如何在PinchGestureRecognizer上保持縮放比例?
我該怎麼辦?
這裏是我的代碼
scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollView.frame = self.view.bounds;
scrollView.backgroundColor = [UIColor blueColor];
scrollView.contentSize = CGSizeMake(imgView.bounds.size.width+100, imgView.bounds.size.height);
scrollView.frame = CGRectMake(0,50,320,500);
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.pagingEnabled = YES;
scrollView.bouncesZoom = YES;
scrollView.minimumZoomScale = 3.0;
scrollView.maximumZoomScale = 6.0;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
[self.view addSubview:scrollView];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinchGesture:)];
[scrollView addGestureRecognizer:pinchGesture];
img =[UIImage imageNamed:[NSString stringWithFormat:@"a.jpg"]];
imgView = [[UIImageView alloc]initWithImage:img];
imgView.frame = CGRectMake(0,0, self.view.frame.size.width, 448);
imgView.userInteractionEnabled = YES;
[scrollView imgView];
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)sender {
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
imgView.transform = CGAffineTransformMakeScale(factor, factor);
NSLog(@"factor %f",factor);
}
可能重複 - iPhone iOS](http://stackoverflow.com/questions/5150642/max-min-scale-of-pinch-zoom-in-uipinchgesturerecogni zer-iphone-ios) –
我可以做到!非常感謝! – zmbdr