So I'm learning how to make views animate from out of screen, to use as slider-menus.
class ViewController: UIViewController {
    @IBOutlet weak var red: UIView!
    @IBOutlet weak var redHConstraint: NSLayoutConstraint!
    @IBAction func buttonShift(sender: AnyObject) {
        self.view.layoutIfNeeded()        // **HERE**
        UIView.animateWithDuration(0.5) {
            self.redHConstraint.constant = 0
            self.view.layoutIfNeeded()    // And **HERE**
        }
    }
}
i've adapted this code from How to animate a UIView with constraints in Swift?
1. What does self.view.layoutIfNeeded() part of the code do?
2. Why is it coded 2x, before and during animation?
Note: if i comment-out the 1st self.view.layoutIfNeeded() nothing changes, but if i comment-out the 2nd self.view.layoutIfNeeded() the movement is no longer animated and just appears in the new coordinates.
 
     
    