I am animating a button to move from the center of a view to a corner and want to know how to make it stay there after I rotate the device. I mocked up a very simple app to show the issue. Here is the example storyboard:
The constraints are added to the appropriate IBOutletCollection in the ViewController and the Button action is linked to the IBAction sendToCorner in the example ViewController:
import UIKit
class ViewController: UIViewController {
@IBOutlet var centerConstraints: [NSLayoutConstraint]!
@IBOutlet var cornerConstraints: [NSLayoutConstraint]!
@IBAction func sendToCorner() {
NSLayoutConstraint.deactivate(centerConstraints)
NSLayoutConstraint.activate(cornerConstraints)
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}
}
The animation from the center to the corner works. However if I rotate the device after I send the button to the corner it returns to the center. My question is: how to permanently send the button to the corner with an animation? Or more generically, how to animate constraints and make the constraints active state permanent through device rotations.