Reputation: 823
I'm currently experimenting with UIView animations in Swift. Im trying to resize a button from (309, 452, 0, 0) to (400, 400, 150, 150). I have the code:
override func viewDidAppear(animated: Bool) {
UIView.animateWithDuration(0.5, animations: {
self.start.bounds = CGRectMake(400, 400, 150, 150)
println(self.start.bounds);
});
}
However, the button just suddenly appears from nothing (no transition) to 150x150 and transitions all the way to the top left corner (0,0). Even though the print statement prints out (309, 452, 150, 150) in the console, it does not to have that frame. I have also tried changing self.start.bounds to self.start.frame, but that doesn't do anything different.
Upvotes: 2
Views: 1034
Reputation: 1218
I think the problem is Auto Layout. I have started a new project with a ViewController and a start button. When I try to change the buttons frame in viewDidLoad
with
UIView.animateWithDuration(1.0) {
self.start.frame = CGRectMake(100, 500, 500, 50);
}
The only thing that happens is the button text being fade in. When I disable AutoLayout or SizeClasses for the View Controller, the button is animated correctly.
Upvotes: 3