/// Rotates An SCNNode Around It's YAxis
///
/// - Parameter gesture: UIRotationGestureRecognizer
@objc func rotateNode(_ gesture: UIRotationGestureRecognizer){
//1. Get The Current Rotation From The Gesture
let rotation = Float(gesture.rotation)
//2. If The Gesture State Has Changed Set The Nodes EulerAngles.y
if gesture.state == .changed{
currentNode.eulerAngles.y = currentAngleY + rotation
}
//3. If The Gesture Has Ended Store The Last Angle Of The Cube
if(gesture.state == .ended) {
currentAngleY = currentNode.eulerAngles.y
}
}
1 回答
旋转
SCNNode
是一项相当简单的任务。您应该首先创建一个变量来将 rotationAngle 存储在 YAxis 周围或您希望在 e.g 上执行旋转的任何其他变量:
您还需要有一些方法来检测要旋转的节点,在本例中我们将调用 currentNode e.g.
在这个例子中,我将围绕 YAxis 旋转。
如果你想使用
UIPanGestureRecognizer
,你可以这样做:或者,如果你想使用
UIRotationGesture
,你可以这样做:希望能帮助到你...