             prevLocation = location
         }
     }
-    
-    deinit {
-        if (motionManger.isDeviceMotionActive) {
-            motionManger.stopDeviceMotionUpdates()
-        }
-    }
-    
-}
+}
+
 
 extension CMDeviceMotion {
     

}

@objc public class CTPanoramaController: UIViewController {

    override public var shouldAutorotate: Bool {
        return true
    }
    
    override public var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .all
    }
    
    override public var prefersStatusBarHidden: Bool {
        return true
    }
    
    public var image: UIImage?
    public var controlMethod = CTPanaromaControlMethod.Touch
    public var panaromaType = CTPanaromaType.Cylindirical
    public var speed = CGPoint(x: 0.005, y: 0.005)
    
    private var sceneView: SCNView!
    private let cameraNode = SCNNode()

        
        scene.rootNode.addChildNode(cameraNode)
        scene.rootNode.addChildNode(geometryNode)
        
        sceneView.scene = scene
        sceneView.backgroundColor = UIColor.black
    }
    
    private func prepareUI() {
        sceneView = SCNView()
        sceneView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(sceneView)
        
        let button = UIButton(type: .custom)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.setTitle("Touch/Motion", for: .normal)
        button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
        
        view.addSubview(button)
        
        let views = ["sceneView" : sceneView, "button": button]
        
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "|[sceneView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[sceneView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
        
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "[button]-10-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
        view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-10-[button]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views))
    }
    
    private func switchControlMethod(to method: CTPanaromaControlMethod) {
        if (method == .Touch) {
            let panGestureRec = UIPanGestureRecognizer(target: self, action: #selector(handlePan(panRec:)))
            sceneView.addGestureRecognizer(panGestureRec)
            
            if (motionManger.isDeviceMotionActive) {
                motionManger.stopDeviceMotionUpdates()
            }
        }
        else {
            guard motionManger.isDeviceMotionAvailable else {return}
