ルート ビュー コントローラーの viewDidLoad に、方向検出用のオブザーバーを追加しました。
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willRotateToInterfaceOrientation:duration:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
次のようなメソッドを追加しました。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
NSLog(@"%f,%f",self.view.frame.size.width,self.view.frame.size.height);
}
私は、ポートレートで 768,1004、ランドスケープで 1004,768 という結果を期待していました。しかし、私の結果は両方とも 768,1004 です。ポートレートの場合は 748,1024 になることもあります。この奇妙な動作の理由がわかりません。解決策を知っている場合は、私を助けてください。
編集 この同じコードは私の別のプロジェクトで機能し、それらの違いを見つけることができませんでした