iOS Pinch Zoom Start from Previous Scale

北战南征 提交于 2019-12-12 01:19:57

问题


I want to do a pinch/zoom having the zoom start at the current scale. I have tried the following code:

@objc func pinchedView(recognizer:UIPinchGestureRecognizer) {

    if (recognizer.state == .ended)  {
        lastScale = 1.0
        return
    }

    let scale = 1.0 - (lastScale - recognizer.scale)
    let zoomInAction = SKAction.scale(to: cameraNode.yScale + scale, duration: 0.25)
    lastScale = recognizer.scale
    cameraNode.run(zoomInAction)
}

The problem is that it keeps getting smaller and smaller no matter which way I pinch. How can I correct this?


回答1:


I think you might instead want to initialize lastScale to 1.0 when your gesture begins.

Look at the accepted answer to this question.



来源:https://stackoverflow.com/questions/53963768/ios-pinch-zoom-start-from-previous-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!