Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift animation with constraint

Is it possible to make a UIView animation by changing constraints?

Basically, I want to animate myv (UIView) which has x, y, height and width constraints, using: UIView.animateWithDuration(1.5) {} by changing the old constraints.

like image 879
ramsserio Avatar asked Jul 25 '16 18:07

ramsserio


1 Answers

Yes this is possible. You can do something like this:

func AnimateHeight() {
    UIView.animateWithDuration(1.5, animations: {
         self.heightCons.constant = 250 // Some value
         self.view.layoutIfNeeded()    
    })
}

Where self.heightCons is an IBOutlet to the height constraint on the UIView.

If you don't use storyboards you can check out how to create layout constraints programmatically.

For info on Core Animation and Auto layout: Combining autolayout with core animation

like image 171
Wyetro Avatar answered Oct 25 '22 14:10

Wyetro