You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #11345, we fixed a UIWindow rotation issue by keeping the UIWindow visible and hiding it on the next run loop (DispatchQueue.main.async). After talking to Apple engineers at WWDC, it looks like we can avoid doing the hack by moving the NoticePresenter initialization to didFinishLaunchingWithOptions instead of willFinishLaunchingOptions.
Here is a sample code showing that this works. You will have to create an empty application with a single view and replace the AppDelegate contents.
import UIKit
@UIApplicationMainclassAppDelegate:UIResponder,UIApplicationDelegate{varwindow:UIWindow?privatevarsecondWindowPresenter:SecondWindowPresenter?func application(_ application:UIApplication, didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?)->Bool{// Move this to willFinishLaunchingWithOptions to reproduce the rotation bug
secondWindowPresenter =SecondWindowPresenter()return true
}func application(_ application:UIApplication, willFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?=nil)->Bool{
window =UIWindow(frame:UIScreen.main.bounds)
window?.backgroundColor =UIColor.white
window?.rootViewController =ViewController()
window?.makeKeyAndVisible()// If this is in -didFinishLaunchingWithOptions, the rotation works fine// secondWindowPresenter = SecondWindowPresenter()return true
}}privateclassSecondWindowPresenter{privateletwindow:UIWindowinit(){letwindowFrame:CGRect
if let mainWindow =UIApplication.shared.keyWindow {
windowFrame = mainWindow.offsetToAvoidStatusBar()}else{
windowFrame =.zero
}
window =UntouchableWindow(frame: windowFrame)
window.windowLevel =.alert
window.backgroundColor =UIColor.blue.withAlphaComponent(0.4)// Emulate showing the Notice (inside a UIWindow)DispatchQueue.main.asyncAfter(deadline:.now()+.seconds(1)){[weak self]inself?.window.isHidden = false
}}}privateextensionUIWindow{func offsetToAvoidStatusBar()->CGRect{returnself.frame.insetBy(dx:Offsets.minimalEdgeOffset, dy:Offsets.minimalEdgeOffset)}privateenumOffsets{staticletminimalEdgeOffset:CGFloat= 1.0
}}@objcclassUntouchableWindow:UIWindow{overrideinit(frame:CGRect){
super.init(frame: frame)
rootViewController =UIViewController()}requiredinit?(coder aDecoder:NSCoder){fatalError("init(coder:) has not been implemented")}}
Proposed Tasks
Verify that the fix works and there are are no regressions.
In #11345, we fixed a
UIWindow
rotation issue by keeping theUIWindow
visible and hiding it on the next run loop (DispatchQueue.main.async
). After talking to Apple engineers at WWDC, it looks like we can avoid doing the hack by moving theNoticePresenter
initialization todidFinishLaunchingWithOptions
instead ofwillFinishLaunchingOptions
.Here is a sample code showing that this works. You will have to create an empty application with a single view and replace the
AppDelegate
contents.Proposed Tasks
@nheagy
The text was updated successfully, but these errors were encountered: