【问题标题】:Getting details about the pinch gesture in ARKit在 ARKit 中获取有关捏合手势的详细信息
【发布时间】:2018-02-05 05:40:03
【问题描述】:

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

谢谢

【问题讨论】:

标签: ios swift scenekit augmented-reality arkit


【解决方案1】:

在 ARSCNView 的主 ViewController 类中

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

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
}

【讨论】:

  • 谢谢你
最近更新 更多