endqwerty
endqwerty

Reputation: 81

move UIImageView coordinates using swift

ballImage.frame = CGRectOffset( ballImage.frame, 10, 10)

This will move the ballImage object 10px down and to the right for a brief second before resetting and returning to its original location. I need it to move and stay.

Upvotes: 0

Views: 216

Answers (1)

Duncan C
Duncan C

Reputation: 131418

Most of us use AutoLayout these days. If so you can't move the frame because the constraints move the view right back again.

In that case, what you have to do is to add horiztonal and vertical constraints to the view you want to move, connect them to outlets, and then in your code modify the constant value of those constraints and call layoutIfNeeded() to trigger the constraint changes to take effect. If you put the call to layoutIfNeeded inside a UIView animateWithDuration call, the change is animated.

Upvotes: 1

Related Questions