Last active
May 16, 2020 14:15
-
-
Save literalpie/3f6b06ddf9cffd540acb661fbfb2a0b2 to your computer and use it in GitHub Desktop.
shows a simple pan gesture handler for use in part 2 of a literalpie medium post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc func handlePan(panGesture: UIPanGestureRecognizer) { | |
guard let view = view as? SCNView else { return } | |
let location = panGesture.location(in: self.view) | |
switch panGesture.state { | |
case .began: | |
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return } | |
// panStartZ and draggingNode should be defined in the containing class | |
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z) | |
draggingNode = hitNodeResult.node | |
case .changed: | |
let location = panGesture.location(in: view) | |
let worldTouchPosition = view.unprojectPoint(SCNVector3(location.x, location.y, panStartZ!)) | |
draggingNode?.worldPosition = worldTouchPosition | |
default: | |
break | |
} | |
} |
You should be able to add it to the viewController, outside the function shown in this gist:
var lastPanLocation: SCNVector3?
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
...
}
here is the appropriate code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to define: lastPanLocation variable?