UIView does not handle rotations, UIViewController does. So, all you need to do is create a UIViewController that implements shouldAutorotateToInterfaceOrientation and sets this controller as rootViewController in your UIWindow
Something like that:
UIViewController * vc = [[[MyViewController alloc] init] autorelease]; vc.view.frame = [[UIScreen mainScreen] bounds]; vc.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4]; //you vc.view initialization here UIWindow * window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; window.windowLevel = UIWindowLevelStatusBar; window.backgroundColor = [UIColor clearColor]; [window setRootViewController:vc]; [window makeKeyAndVisible];
and I used this MyViewController because I want it to reflect the changes in the main application
@interface MyViewController : UIViewController @end @implementation MyViewController - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { UIWindow *window = ((UIWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0]); UIViewController *controller = window.rootViewController; if (!controller) { NSLog(@"%@", @"I would like to get rootViewController of main window"); return YES; } return [controller shouldAutorotateToInterfaceOrientation:toInterfaceOrientation]; } @end
but you can always just return YES for any orientation or write your own logic if you want.
Mark pervovskiy
source share