UIViewControllerのviewWillAppearメソッドでインターフェイスの向きを取得する必要があります。私がしたことは:
if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
NSLog(@"Portrait");
else
NSLog(@"Landscape");
横向きの場合、常にviewWillAppearでPortraitを取得し、viewDidAppearでLandscapeを取得します。なんで?
そこで、[[UIApplication sharedApplication] statusBarOrientation]を使ってみましたが、同じことが起こります。StackOverflowに掲載されている別のソリューションも試しました。
UIDevice* device = [UIDevice currentDevice];
[device beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation currentOrientation = device.orientation;
[device endGeneratingDeviceOrientationNotifications];
これは向きを正しく返すように見えますが、UIDeviceOrientationをUIInterfaceOrientationにマッピングする問題が残っています。これは、私が知る限り不可能です(上向きと下向きはマッピングできません)。
この問題の解決策はありますか?