Search code examples
iosuiviewrotationuitabbaruiwindow

UIView added on top of window does not rotate on iOS


I have a tabBar based application and want to present some custom view above whole screen (not as modal view) and I do it like that:

[self.view.window addSubview:self.myViewController.view];

The reason I did this is because this way view is positioned above UITabBar.

Anyway view is presented nicely and it covers whole screen like I want to. But there is a problem. When I rotate device this top view does not rotate, but view's underneath do.

I've tested on iOS5 and iOS6 without luck. Have also put this code in delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskAll;
}

Similar code is in myViewController's view:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

The view just doesn't rotate... ?


Solution

  • As far as i know only the first subview of the window gets the rotation events. You're adding another view (your view) to the window and therefore need to deal with propagating the rotation events yourself.

    Providing some really quick-help for you, just check out the following implementation : AGWindowView (not maintained from 2016)