使用Pinch手势在运行时缩放SCNNode [英] scaling a SCNNode in runtime using the Pinch gesture

查看:58
本文介绍了使用Pinch手势在运行时缩放SCNNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Pinch手势实时缩放和SCNNode:

I am trying to scale and SCNNode in real time using the Pinch gesture:

这是我当前的代码

let pinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(from:)))
sceneView.addGestureRecognizer(pinchGestureRecognizer)

@objc
func handlePinch(from recognizer: UIPinchGestureRecognizer){
  var pinchScale = recognizer.scale
  pinchScale = round(pinchScale * 1000) / 1000.0

  sceneView.scene.rootNode.enumerateChildNodes { (node, stop) -> Void in
    if(node.name == "Box01"){
       node.scale = SCNVector3(x: pinchScale, y: pinchScale, z: pinchScale)
    }
  }        
}

然而,节点的规模却没有变大还是变小?有人可以指出我的错误吗?

However the node doesn't scale big or small? Can someone please point my mistake?

已加载SCNNode并在其上应用了动画,

The SCNNode is loaded and has an animation on applied like so,

sceneView.scene.rootNode.addChildNode(node)
loadAnimation(animation: .Attack, sceneName: "art.scnassets/attack", animationIdentifier: "attackID");

推荐答案

我用它来处理比例尺:

@objc
func handlePinch(from recognizer: UIPinchGestureRecognizer){
    var pinchScale = round(recognizer.scale * 1000)/1000000
    let node_arm = sceneView.scene.rootNode.childNode(withName: "army", recursively: true)
    node_arm?.runAction(.customAction(duration: 0, action: { node, progress in
        node.physicsBody = nil
        node.scale = SCNVector3(x: Float(pinchScale), y: Float(pinchScale), z: Float(pinchScale))
    }))
}

这篇关于使用Pinch手势在运行时缩放SCNNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆