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.