UIViewは回転を処理しません。UIViewControllerは回転を処理しません。 だから、あなたが必要とするすべてはshouldAutorotateToInterfaceOrientationを実装し、あなたのUIWindowにそのような
何かrootViewControllerとして、このコントローラを設定のUIViewController、作成することです:
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];
を、私はそれをしたい原因私は、このMyViewControllerを使用しましたメインアプリケーションの変更
@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
を反映していますが、常にちょうどあなたが希望する場合は、任意の方向にYESを返すか、あなたのロジックを記述することができます。
私は同様の問題があります - UIWindowとそのビューは回転していないようです - この解決法はうまくいかないようです私のために。私は、ウィンドウのrootViewControllerを正常にそのサブビューを回転させるコントローラーにしますが、ウィンドウのサブビューはまったく回転しません。 –
そして、それらはUIViewControllerには添付されておらず、UIViewControllerだけが回転を管理するべきではありません。 –
これは素晴らしい答えです。ありがとうございます。これは、二次ウィンドウ "Just Work"でローテーションを行います。ウィンドウを後で画面から削除するには、そのrootViewControllerをnilに設定し、その参照も自身に設定してください。そうすれば、ARCはそれを割り当て解除できます。 – nobre