             guard let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)! as? DTPhotoViewerController else {
                 fatalError("view controller does not conform DTPhotoViewer")
             }
-            let fromView = fromViewController.view
-            let toView = toViewController.view
+            let fromView = fromViewController.view!
+            let toView = toViewController.view!
+            toView.frame = container.bounds
             
             let completeTransition: () -> () = {
-                // Add subview before completing transition
-                UIApplication.shared.delegate?.window??.addSubview(toViewController.view)
-                
                 let isCancelled = transitionContext.transitionWasCancelled
                 transitionContext.completeTransition(!isCancelled)
-                
-                if isCancelled {
-                    container.insertSubview(toView!, belowSubview: fromView!)
-                }
             }
             
-            container.addSubview(fromView!)
-            container.addSubview(toView!)
+            container.addSubview(toView)
             
             if spring {
                 UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: kDamping, initialSpringVelocity: kInitialSpringVelocity, options: UIViewAnimationOptions.curveEaseOut, animations: {
                     //Animate image view to the center
                     toViewController.presentingAnimation()
-                    }, completion: { (finished) in
-                        toViewController.presentingEnded()
-                        completeTransition()
+                }, completion: { (finished) in
+                    toViewController.presentingEnded()
+                    completeTransition()
                 })
             }
             else {

                    //Hide status bar
                    toViewController.presentingEnded()
                    completeTransition()
                }) 
            }
            
        }

                    //End transition
                    fromViewController.dismissingEnded()
                    completeTransition()
                })
            }
        }
    }
