Swift 3 UIView animation Swift 3 UIView animation swift swift

Swift 3 UIView animation


I had this problem too with the newest update to swift 3.

To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view.

Try this instead:

UIView.animate(withDuration: 0.1,           delay: 0.1,           options: UIViewAnimationOptions.curveEaseIn,           animations: { () -> Void in               constraint.constant = ButtonAnimationValues.YPosition.DefaultOut()               self.superview?.layoutIfNeeded()}, completion: { (finished) -> Void in// ....})

It seems in the past they've been lenient about being able to just relayout the view you want to animate. But its in the documentation that you should really be calling layoutIfNeeded in the superview.


Upgrade to swift 3.0

View right to left animation like apple default push animation

//intially set x = SCREEN_WIDTHview.frame = CGRect(x: ScreenSize.SCREEN_WIDTH, y: ScreenSize.SCREEN_HEIGHT - heightTabBar , width: ScreenSize.SCREEN_WIDTH, height: heightTabBar)UIView.animate(withDuration: 0.50, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: [], animations: { //Set x position what ever you want                        view.frame = CGRect(x: 0, y: ScreenSize.SCREEN_HEIGHT - heightTabBar , width: ScreenSize.SCREEN_WIDTH, height: heightTabBar)                    }, completion: nil)


First set the new value for your constraint and then call animate.

self.YOUR_CONSTRAINT.constant = NEW_VALUEUIView.animate(withDuration: 1.0) {    self.view.layoutIfNeeded()}