                 oldController.view.removeFromSuperview()
                 oldController.removeFromParentViewController()
             }
-            if let drawerViewController = drawerViewController {
-                let viewDictionary      = ["drawerView" : drawerViewController.view]
-                let itemAttribute: NSLayoutAttribute
-                let toItemAttribute: NSLayoutAttribute
-                switch drawerDirection {
-                case .Left:
-                    itemAttribute   = .Right
-                    toItemAttribute = .Left
-                case .Right:
-                    itemAttribute   = .Left
-                    toItemAttribute = .Right
-                }
-                
-                drawerViewController.view.layer.shadowColor   = UIColor.blackColor().CGColor
-                drawerViewController.view.layer.shadowOpacity = 0.4
-                drawerViewController.view.layer.shadowRadius  = 5.0
-                drawerViewController.view.translatesAutoresizingMaskIntoConstraints = false
-                addChildViewController(drawerViewController)
-                _containerView.addSubview(drawerViewController.view)
-                drawerViewController.view.addConstraint(
-                    NSLayoutConstraint(
-                        item: drawerViewController.view,
-                        attribute: NSLayoutAttribute.Width,
-                        relatedBy: NSLayoutRelation.Equal,
-                        toItem: nil,
-                        attribute: NSLayoutAttribute.Width,
-                        multiplier: 1,
-                        constant: drawerWidth
-                    )
+            guard let drawerViewController = drawerViewController else { return }
+            let viewDictionary      = ["drawerView" : drawerViewController.view]
+            let itemAttribute: NSLayoutAttribute
+            let toItemAttribute: NSLayoutAttribute
+            switch drawerDirection {
+            case .Left:
+                itemAttribute   = .Right
+                toItemAttribute = .Left
+            case .Right:
+                itemAttribute   = .Left
+                toItemAttribute = .Right
+            }
+            
+            drawerViewController.view.layer.shadowColor   = UIColor.blackColor().CGColor
+            drawerViewController.view.layer.shadowOpacity = 0.4
+            drawerViewController.view.layer.shadowRadius  = 5.0
+            drawerViewController.view.translatesAutoresizingMaskIntoConstraints = false
+            addChildViewController(drawerViewController)
+            _containerView.addSubview(drawerViewController.view)
+            _drawerWidthConstraint = NSLayoutConstraint(
+                item: drawerViewController.view,
+                attribute: NSLayoutAttribute.Width,
+                relatedBy: NSLayoutRelation.Equal,
+                toItem: nil,
+                attribute: NSLayoutAttribute.Width,
+                multiplier: 1,
+                constant: drawerWidth
+            )
+            drawerViewController.view.addConstraint(_drawerWidthConstraint)
+            
+            _drawerConstraint = NSLayoutConstraint(
+                item: drawerViewController.view,
+                attribute: itemAttribute,
+                relatedBy: NSLayoutRelation.Equal,
+                toItem: _containerView,
+                attribute: toItemAttribute,
+                multiplier: 1,
+                constant: 0
+            )
+            _containerView.addConstraint(_drawerConstraint)
+            _containerView.addConstraints(
+                NSLayoutConstraint.constraintsWithVisualFormat(
+                    "V:|-0-[drawerView]-0-|",
+                    options: [],
+                    metrics: nil,
+                    views: viewDictionary
                 )
-                _drawerConstraint = NSLayoutConstraint(
-                    item: drawerViewController.view,
-                    attribute: itemAttribute,
-                    relatedBy: NSLayoutRelation.Equal,
-                    toItem: _containerView,
-                    attribute: toItemAttribute,
-                    multiplier: 1,
-                    constant: 0
-                )
-                _containerView.addConstraint(_drawerConstraint)
-                _containerView.addConstraints(
-                    NSLayoutConstraint.constraintsWithVisualFormat(
-                        "V:|-0-[drawerView]-0-|",
-                        options: [],
-                        metrics: nil,
-                        views: viewDictionary
-                    )
-                )
-                drawerViewController.didMoveToParentViewController(self)
-            }
+            )
+            _containerView.updateConstraints()
+            drawerViewController.updateViewConstraints()
+            drawerViewController.didMoveToParentViewController(self)
         }
     }
     

        default:
            return touch.view == gestureRecognizer.view
        }
    }


}


        return gesture
    }()
    
    public weak var delegate: KYDrawerControllerDelegate?
    
    public var drawerDirection: DrawerDirection = .Left {
        didSet {
            switch drawerDirection {
            case .Left:  screenEdgePanGesture.edges = .Left
            case .Right: screenEdgePanGesture.edges = .Right
            }
            let tmp = drawerViewController
            drawerViewController = tmp
        }
    }
    
    public var drawerState: DrawerState {
        get { return _containerView.hidden ? .Closed : .Opened }
        set { setDrawerState(drawerState, animated: false) }
    }
    
    @IBInspectable public var drawerWidth: CGFloat = 280 {
        didSet { _drawerWidthConstraint?.constant = drawerWidth }
    }
    
    public var mainViewController: UIViewController! {
        didSet {
