理由 :
この問題には多くの可能性があります。
1) ビューviewController
がではないsubView
他のビューである場合、回転呼び出しがサブビューのコントローラーに伝達されない可能性があります。rootViewController
navigationController
2)Super
メソッドが必要な場所で適切に呼び出されない場合、それが回転の問題の原因である可能性があることをどこかで読みました。つまり、自動回転に関連するビュースタック内のすべての ViewControllers はsuper
、メソッド実装でメソッドを呼び出す必要があります (つまり、[super viewDidLoad]
ViewController からviewDidLoad
)。
以下のトリックを使用して、向きの変更を処理できます。
viewWillAppear にノーティファイアを登録します。
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}
向きの変更は、以下の関数に通知されます。
- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}
これにより、方向の変更を処理できる以下のメソッドが呼び出されます。
- (void) handleOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//handle the portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//handle the landscape view
}
}