Quantcast
Channel: How to animate a UIImage constraints in Swift 4 - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by heyfrank for How to animate a UIImage constraints in Swift 4

$
0
0

I think you're confusing UIImage with UIImageView. The first one is the image's data representation, the second one is the View that displays the UIImage.

So I guess you want to move around the UIImageView. To do that obtain a reference to the constraints (e.g. by ctrl-dragging from the constraint in the storyboard to your UIViewController instance).

After that you can update the constraint in an animation block like here:

// Make sure the view is laid out as Mischanya Schtrigel statedself.view.layoutIfNeeded() UIView.animate(withDuration: 0.5) { // duration in seconds    myConstraint.constant = 50 // update your constraint here    self.view.layoutIfNeeded()}

Contrary to the other answers, I like putting the constraint changes in the animation closure to make it more clear what is going to be animated.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>