简体   繁体   English

iOS Pinch缩放从上一个比例开始

[英]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. 我认为您可能想在手势开始时将lastScale初始化为1.0。

Look at the accepted answer to this question. 查看此问题的公认答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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