捏手势IOS的手势绑定限制

时间:2016-08-11 10:25:12

标签: ios uigesturerecognizer uipinchgesturerecognizer

我正在使用捏合手势来缩小图像。现在,我可以设置下限到该限制的限制,它不会让用户缩小。我正在使用下面的代码。

func handlePinch(recognizer : UIPinchGestureRecognizer)
    {
        imageView.transform = CGAffineTransformScale(imageView.transform,
                                                         recognizer.scale, recognizer.scale)

        recognizer.scale = 1.0
}

3 个答案:

答案 0 :(得分:1)

我已经使用一些静态变量完成了

var cumulativeScale:CGFloat = 1.0
var maxScale:CGFloat = 3.5
var minScale:CGFloat = 0.5

@IBAction func zoomingInAndOut(_ pinchGesture: UIPinchGestureRecognizer) {
        guard pinchGesture.view != nil else {return}

        if pinchGesture.state == .began || pinchGesture.state == .changed{
            if (cumulativeScale < maxScale && pinchGesture.scale > 1.0) {
                pinchGesture.view?.transform = (pinchGesture.view?.transform)!.scaledBy(x: pinchGesture.scale, y: pinchGesture.scale)
                cumulativeScale *= pinchGesture.scale
                pinchGesture.scale = 1.0
            }
            if (cumulativeScale > minScale && pinchGesture.scale < 1.0) {
                pinchGesture.view?.transform = (pinchGesture.view?.transform)!.scaledBy(x: pinchGesture.scale, y: pinchGesture.scale)
                cumulativeScale *= pinchGesture.scale
                pinchGesture.scale = 1.0
            }
        }
    }

答案 1 :(得分:0)

git stash save --include-untracked

答案 2 :(得分:-2)

没有直接方式来限制UIPinchGestureRecogniser的规模。 但是你可以尝试这里描述的技术:

Max/Min Scale of Pinch Zoom in UIPinchGestureRecognizer - iPhone iOS