Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import UIKit
  2. import SceneKit
  3.  
  4. class CustomScrollView: UIView {
  5.  
  6. override init(frame: CGRect) {
  7. super.init(frame: frame)
  8.  
  9. let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panView(with:)))
  10. addGestureRecognizer(panGesture)
  11. }
  12.  
  13. required init?(coder aDecoder: NSCoder) {
  14. super.init(coder: aDecoder)
  15. }
  16.  
  17. @objc fileprivate func panView(with gestureRecognizer: UIPanGestureRecognizer) {
  18.  
  19. let translation: CGPoint = gestureRecognizer.translation(in: self)
  20. UIView.animate(withDuration: 0.20) {
  21. self.bounds.origin.y = self.bounds.origin.y - translation.y
  22. }
  23. gestureRecognizer.setTranslation(.zero, in: self)
  24. }
  25. }
  26.  
  27. @objc func nodeWasTapped(_ recognizer: UITapGestureRecognizer) {
  28.  
  29. guard let sceneView = recognizer.view as? ARSCNView else { return }
  30.  
  31. let touchLocation: CGPoint = recognizer.location(in: sceneView)
  32.  
  33. let hitResults = sceneView.hitTest(touchLocation, options: [:])
  34. if !hitResults.isEmpty {
  35.  
  36. guard let hitResult = hitResults.first else { return }
  37.  
  38. if let node = hitResult.node as? SCNNode {
  39. // ...
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement