获取有关 ARKit 中捏合手势的详细信息

Getting details about the pinch gesture in ARKit

在我的项目中,我有一个用于调整已放置在场景视图中的对象的大小选项。但是当有人捏住屏幕来缩小或放大物体的实际大小时,我需要得到那个比例。我需要在屏幕上显示正在更改对象的比例。如何获取动作执行时的比例?

谢谢

在您的主要 ViewController Class 中用于 ARSCNView

声明标签视图,标签本身位于顶部。

let scaleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, 70))
let labelView = UIView(frame: CGRect(x: 300, y: 300, width: 300, height: 70))

现在,在 LoadView 或 ViewDidLoad 中,您可以设置标签的属性,例如 backgroundColor、textColor 等...,并将视图和标签添加到 sceneView。

// add your attributes for label,view

labelView.backgroundColor = .clear
scaleLabel.textColor = .white
scaleLabel.adjustsFontSizeToFitWidth

// add you views to sceneView

labelView.addSubview(scaleLabel)
sceneView.addSubview(labelView)

最后,使用缩放手势功能..应该看起来像这样。

@objc func pinchGesture(_ gesture: UIPinchGestureRecognizer) {

 if nodeYouScale != nil {

   let action = SCNAction.scale(by: gesture.scale, duration: 0.1)
   nodeYouScale.runAction(action)
   gesture.scale = 1 

    // this part updates the label with the current scale factor 

 scaleLabel.text = "X: \(nodeYouScale.scale.x) Y: \(nodeYouScale.scale.y) Z:\(nodeYouScale.scale.z)"

  } else {
    return
}