views:

810

answers:

1

I have an app that rotates on some (but not all) screens, and I also want to add a UIView as an overlay that shows up on all screens, so I thought I'd add it to the window. The problem now is that when I rotate the device, the screens rotate, but the overlay view does not.

I also tried using two UIViewControllers, one for the normal stuff, one for the overlay view, but I didn't have high hopes for that, and I was right. Only one UIViewController will ever actually rotate.

So how do I rotate the overlay with the interface, hopefully without needing to add code to each view controller that rotates to rotate the overlay with it.

A: 

I think your suspicions are correct. You will have to add the subview to each view controller. I don't know why, but when you add multiple views as subviews of the window, only the first one gets its - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation called on each orientation change.

I haven't tried this, but it seems you could possibly create a single parent view controller you add as a subview of the window that will contain your navigation controller as well as your overlay view controller. Maybe it would correctly call -shouldAutotrotateToInterfaceOrientation. Again this is hypothetical as I haven't tried it, but I am sure that it won't work just to add the overlay view to the window.

Best Regards,

Matt Long