我想在已攻丝节点的场景视图中获得矩形位置,以便可以使用该位置将另一个UIView从该位置动画化为更大的尺寸(就像在Measure应用程序中一样):
尽管我如何获取rect
或尺寸或任何东西以使从节点到视图的平滑过渡,但我仍获得了这段代码来窃听节点?
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
guard let touch = touches.first else { return }
if (touch.view == self.sceneView) {
let viewTouchLocation:CGPoint = touch.location(in: sceneView)
guard let result = sceneView.hitTest(viewTouchLocation, options: nil).first else {
return
}
}
}
我已经考虑在给定触摸位置的情况下在场景视图上使用hitTest
或smartHitTest
,但我似乎无法真正获得较小视图的大小/位置。 / p>
答案 0 :(得分:1)
并非完全是您的答案,而是尝试一下:(已编辑以将其发送回去)
var front = false
var boxView = UIView()
@objc func tap(_ sender: UITapGestureRecognizer){
if !front{
let position = sender.location(in: sceneView)
let hitTest = sceneView.hitTest(position, options: nil)
if let hitNode = hitTest.first?.node{
self.boxView = UIView(frame: CGRect(x: position.x, y: position.y, width: 100, height: 40))
self.boxView.backgroundColor = .red
sceneView.addSubview(self.boxView)
UIView.animate(withDuration: 0.2) {
self.boxView.frame = CGRect(x: self.sceneView.frame.width/2 - 150, y: self.sceneView.frame.height/2 - 100, width: 300, height: 200)
}
front = true
}
}else{
let p = plane.convertPosition(plane.position, to: sceneView.scene.rootNode)
print(p, plane.position) // see difference between p and plane.position
let projectedPoint = sceneView.projectPoint(p)
let point = CGPoint(x: CGFloat(projectedPoint.x), y: CGFloat(projectedPoint.y))
UIView.animate(withDuration: 0.2, animations: {
self.boxView.frame = CGRect(x: point.x, y: point.y, width: 100, height: 40)
}) { (completed) in
self.boxView.removeFromSuperview()
}
front = false
}
}
plane
这是我的测试案例中的节点。您可能想看看convertPosition和projectPoint