简体   繁体   中英

iOS Pinch Zoom Start from Previous Scale

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?

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

Look at the accepted answer to this question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM