Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import SceneKit
- class CustomScrollView: UIView {
- override init(frame: CGRect) {
- super.init(frame: frame)
- let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panView(with:)))
- addGestureRecognizer(panGesture)
- }
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- @objc fileprivate func panView(with gestureRecognizer: UIPanGestureRecognizer) {
- let translation: CGPoint = gestureRecognizer.translation(in: self)
- UIView.animate(withDuration: 0.20) {
- self.bounds.origin.y = self.bounds.origin.y - translation.y
- }
- gestureRecognizer.setTranslation(.zero, in: self)
- }
- }
- @objc func nodeWasTapped(_ recognizer: UITapGestureRecognizer) {
- guard let sceneView = recognizer.view as? ARSCNView else { return }
- let touchLocation: CGPoint = recognizer.location(in: sceneView)
- let hitResults = sceneView.hitTest(touchLocation, options: [:])
- if !hitResults.isEmpty {
- guard let hitResult = hitResults.first else { return }
- if let node = hitResult.node as? SCNNode {
- // ...
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement