Need a way to determine if additional overlay UIWindows should rotate with main.
| Originator: | heardrwt | ||
| Number: | rdar://10778815 | Date Originated: | |
| Status: | Open | Resolved: | |
| Product: | iphone SDK | Product Version: | |
| Classification: | Enhancment | Reproducible: | NA |
30-Jan-2012 04:23 PM Richard Heard: Need a way to determine if additional overlay UIWindows should rotate with main. (Based on the main windows root view controllers decision wether or not to auto-rotate) Here is the deal. Im a window sitting up above the main app window I'm registered for device orientation change notifications ( [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; ) i receive an orientation changed notification before i handle the orientation change in my window i need to find out if the main app UI will be rotating or not. the only way i can think of querying this is via a call to [[[[UIApplication sharedApplication] keyWindow] rootViewController] shouldAutorotateToInterfaceOrientation:newOrientation] passing in the currentDeviceOrientation This however does not actually work because when i set my overlay window to no longer be hidden, my overlayView is returned as the keyWindow. My overlay view has no controller associated with it, hence has no rootViewController. Even if i did have a controller associated with my window, I'm actually interested in knowing if the main app UI will be rotating or not. This seems like a deficiency in UIWindow etc Some other related issues that make things harder: -- Device orientation and interface orientation are flipped in landscape -- pre iOS5 if a user calls [window addSubview:] is the rootViewController guaranteed to be populated? -- UIWindow keyWindow is not necessarily the apps main window (it could be any current alert / overlay etc) Possible additions that would make this stuff easier: -- Explicit notifications for when the main app window will / did rotate, which include the animated flag -- UIApplication could expose a mainWindow property. (which always pointed to the window of the rootViewController that is asked about autorotation) -- every window that has a rootViewController could be asked shouldAutorotateToInterfaceOrientation:newOrientation, this would make it easier for accessory windows to channel their response from the mainWindow property on UIApplication mentioned in the precious point. -- Have a way to specifically turn autorotation on and off for additional windows, either by use of the previous lines controller goop, or a flag on the window itself. -------a possible (hacky) solution Register and use the UIApplicationWillChangeStatusBarOrientationNotification to detect main window orientation changes. On receipt transform our accessory windows for this new orientation. This seems like a hack in that we are basing our accessory windows transforms off of the status bars orientation, not the main app windows orientation. Other code could specifically call [UIApplication setStatusBarOrientation:] and our overlay window would rotate but the main window would not. Help.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
07-Mar-2012 05:33 PM Richard Heard: Thanks for the quick reply.
I have to use a window instead of being a subview of the root view because we want to show for a limited amount of time over the top of the status bar.
( We present notification information, (from push notifications etc) as a slide down for the top of the screen view that slides over the status bar and the user can tap on to jump to the relevant content. )
Attached is a class/ demo app that would benefit from the enhancements in this area. Ideally we would be able to rotate in sync with the main window just as the UIAlertView can. ATM it implements listening for status bar orientation changes.
>You can use -[UIApplication windows] to find your main window and iterate through the windows asking if they are not hidden AND if [[window rootViewController] shouldAutorotateToInteraceOrientation:...] returns YES.
If an application has more than one window, both of which have a rootViewController and one of which returns YES for portraitUpsideDown and another that does not. I cant assume that the main window will be rotating to portraitUpsideDown just because one of the controllers returned YES, because i dont actually know which root view controller UIKit has asked.
> Your root view controller can post a notification in willRotateToInteraceOrientation:duration: or willAnimateRotationToInterfaceOrientatin:duration.
The class in question is trying to be re-usable in a drop into any app sense and "having the root view controller post rotation notifications" is not exactly elegant.
My original suggestions still stand. Auto rotation for accessory windows provided by UIKit or at-least exposing the mainWindow on the UIApplication singleton would be very very useful.
07-Mar-2012 05:34 PM Richard Heard: Attached RotationalFun.zip
07-Mar-2012 05:34 PM Richard Heard: 'RotationalFun.zip' was successfully uploaded