Pinch 捏合手勢(shì)控制放大縮小倍率和速率
- (void)pinchImage:(UIGestureRecognizer*)sender {
CGAffineTransform tranform = sender.view.transform;
CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]) * 0.5;
//當(dāng)手指離開屏幕時(shí),將lastscale設(shè)置為1.0
if (sender.state == UIGestureRecognizerStateEnded) {
//如果視圖寬度小于屏幕尺寸則恢復(fù)原始transform
if (sender.view.frame.size.width <= SCREEN_WIDTH) {
sender.view.transform = sourceTransform;
}
lastScale = 1.0;
return;
}
if (sender.state == UIGestureRecognizerStateChanged) {
//最大放大2倍配乱,細(xì)小縮放一倍
NSInteger maxSale = 4;
if (sender.view.frame.size.width >= SCREEN_WIDTH * maxSale) {
sender.view.transform = CGAffineTransformScale(sourceTransform, maxSale, maxSale);
return;
}else if (sender.view.frame.size.width <= SCREEN_WIDTH * 0.5) {
sender.view.transform = CGAffineTransformScale(sourceTransform, 0.5, 0.5);
return;
}
}
sender.view.transform = CGAffineTransformScale(tranform,scale, scale);
lastScale = [(UIPinchGestureRecognizer*)sender scale];
}