UIAlertController is moved to buggy position at top of screen when it calls `presentViewController:`
I encountered a situation where sometimes a modal view would present itself on top of a an alert (silly situation, I know), and the UIAlertController could appear in the top left (like the 2nd screenshot of the original question), and I found a one-liner solution that seems to work. For the controller that's about to be presented on the UIAlertController, change its modal presentation style like so:
viewControllerToBePresented.modalPresentationStyle = .OverFullScreen
This should be done just before you call presentViewController(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion completion: (() -> Void)?)
rdar://19037589 was closed by Apple
Apple Developer Relations | 25-Feb-2015 10:52 AM
There are no plans to address this based on the following:
This isn't supported, please avoid presenting on a UIAlertController.
We are now closing this report.
If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.
Please be sure to regularly check new Apple releases for any updates that might affect this issue.
I was having this issue as well. If I presented a view controller while a UIAlertController was presented, the alert would go to the top left.
My fix is to refresh the center of the UIAlertController's view in viewDidLayoutSubviews; achieved by subclassing UIAlertController.
class MyBetterAlertController : UIAlertController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let screenBounds = UIScreen.mainScreen().bounds
if (preferredStyle == .ActionSheet) {
self.view.center = CGPointMake(screenBounds.size.width*0.5, screenBounds.size.height - (self.view.frame.size.height*0.5) - 8)
} else {
self.view.center = CGPointMake(screenBounds.size.width*0.5, screenBounds.size.height*0.5)
}
}
}