Reputation: 4025
If you look at the default alert view, when presented, it stays in exactly the same location during device rotation. It appears to rotate from its own center.
I've made a custom alert view and would like the same behavior. I have a container view which includes a background view (to dim out the screen some) and the alert view. When I rotate, the alert view jumps to what will be the new center after the rotation, then animates into place. How can I get it to rotate from its own center?
Upvotes: 1
Views: 1233
Reputation: 233
Here is Matt's solution in Swift 2+ syntax:
v.autoresizingMask = [.FlexibleTopMargin , .FlexibleBottomMargin , .FlexibleLeftMargin , .FlexibleRightMargin]
v.translatesAutoresizingMaskIntoConstraints = true
Upvotes: 1
Reputation: 534893
The problem is merely that your constraints positioning the alert view are incorrect. If they are correct, centering will happen automatically and will remain in place during rotation.
For example:
v.autoresizingMask = .FlexibleTopMargin | .FlexibleBottomMargin | .FlexibleLeftMargin | .FlexibleRightMargin
v.setTranslatesAutoresizingMaskIntoConstraints(true)
Upvotes: 4