 
     func orientationDidChange() {
         let orientation = UIDevice.currentDevice().orientation
-        let landscapeToLandscape = UIDeviceOrientationIsLandscape(orientation) && UIInterfaceOrientationIsLandscape(lastUsedOrientation)
-        let portraitToPortrait = UIDeviceOrientationIsPortrait(orientation) && UIInterfaceOrientationIsLandscape(lastUsedOrientation)
+        let landscapeToLandscape = UIDeviceOrientationIsLandscape(orientation) && UIDeviceOrientationIsLandscape(lastUsedOrientation)
+        let portraitToPortrait = UIDeviceOrientationIsPortrait(orientation) && UIDeviceOrientationIsLandscape(lastUsedOrientation)
         if landscapeToLandscape || portraitToPortrait {
-            let newOrientation = UIInterfaceOrientation(rawValue: orientation.rawValue)
-            if newOrientation == lastUsedOrientation {
+            guard orientation != lastUsedOrientation else {
                 return
             }
-            lastUsedOrientation = newOrientation!
+            lastUsedOrientation = orientation
             UIView.animateWithDuration(0.6) {
                 [weak self] in
                 self?.updateLayoutsForCurrentOrientation()

            self?.updateLayoutsForCurrentOrientation()
        }) {
            [weak self] _ in
            self?.lastUsedOrientation = UIApplication.sharedApplication().statusBarOrientation
        }
    }


        view.addSubview(spinner)
    }

    private var lastUsedOrientation: UIDeviceOrientation!

    public override func viewWillAppear(animated: Bool) {
        lastUsedOrientation = UIDeviceOrientation(rawValue: UIApplication.sharedApplication().statusBarOrientation.rawValue)
    }

    private var initialOrientation: UIDeviceOrientation!

    public func showFrom(viewController: UIViewController) {
        backgroundSnapshot = UIApplication.sharedApplication().delegate?.window??.rootViewController?.view.snapshot()

        view.userInteractionEnabled = false
        initialOrientation = UIDeviceOrientation(rawValue: UIApplication.sharedApplication().statusBarOrientation.rawValue)
    
        dispatch_async(dispatch_get_main_queue()) {
            self.collectionView.alpha = 0
