Reputation: 168
I'm trying to re-position a UILabel exactly over another UILabel (identical position). Its not positioning itself exactly over the target UILabel.
See code below
let element1yPosition = element1.frame.origin.y. // Element 1 y Position
let element2yPosition = element2.frame.origin.y. // Element 2 y Position
UIView.animate(withDuration: 1.0, animations: {
element1.frame.origin.y = element2yPosition // Repositioning stage.
//Fails because Element 1 doesn't re-position itself in the exact same position as Element 2 as required.
})
Upvotes: 0
Views: 74
Reputation: 105
element1.frame.origin.y is a number in struct. element1 didn't know his's frame.origin.y changed. if You want to change a UIView's position, you should change it's frame,center,transform.
Upvotes: -1
Reputation: 100503
Can you try
UIView.animate(withDuration: 1.0, animations: {
element1.frame = element2.frame
})
Upvotes: 2