1.声明变量
CGFloat deviceZoom;
CGFloat lastZoome;
2.在视图上 添加缩放手势
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[self.videoView addGestureRecognizer:pinchGestureRecognizer];
3.实现方法
- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer {
CGFloat zoomSize = recognizer.scale;
if ( zoomSize > 1 ) { // 放大
if (zoomSize > lastZoome) {
deviceZoom = zoomSize - lastZoome + deviceZoom;
if (deviceZoom >5) {
deviceZoom = 5;
}
}
} else { // 缩小
if (zoomSize < lastZoome) {
deviceZoom = deviceZoom - (1 - zoomSize);
if (deviceZoom < 1) {
deviceZoom = 1;
}
}
}
lastZoome = zoomSize;
}
deviceZoom 就是最后得到的比例
网友评论