Reputation: 13
I am trying to move a UILabel and a UIButton onto the screen of my app once something happens, however, when I use an animation to do this, it doesn't work and when the animation is supposed to happen, the components don't move onto the screen. Here is the code for the animation:
UIView.animateWithDuration(2) { () -> Void in
self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
self.again.center = CGPointMake(self.view.center.x, self.again.center.y)
}
Any help with this problem will be greatly appreciated!
Upvotes: 0
Views: 1323
Reputation: 5039
Try this!
UIView.animateWithDuration(1.0,
delay: 2.0,
options: .CurveEaseInOut ,
animations: {
self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
self.again.center = CGPointMake(self.view.center.x, self.again.center.y) },
completion: { finished in
println("Bug moved left!")
self.faceBugRight()
})
}
Upvotes: 0
Reputation: 2589
You should try this. Using layoutIfNeeded() will reposition everything.
UIView.animateWithDuration(2) { () -> Void in
self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
self.again.center = CGPointMake(self.view.center.x, self.again.center.y)
self.view.layoutIfNeeded()
}
Upvotes: 1