Search code examples
iosscenekit

Disable camera panning in SceneKit


If I am using the default camera control in SceneKit, is there a way to disable the two fingered pan function and leave the others as they are?

I want users to be able to rotate and zoom an object, but not move it at all.


Solution

  • The sceneView already has a UIPanGestureRecognizer attached. If you modify its maximumNumberOfTouches to be 1, you can disable the pan gesture.

    for reco in sceneView.gestureRecognizers! {
        if let panReco = reco as? UIPanGestureRecognizer {
            panReco.maximumNumberOfTouches = 1
        }
    }