1

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にマッピングする問題が残っています。これは、私が知る限り不可能です(上向きと下向きはマッピングできません)。

この問題の解決策はありますか?

4

2 に答える 2

0

代わりに[UIApplicationsharedApplication].statusBarOrientationを使用してください。

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    // Portrait
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
    // Landscape
}
于 2012-07-04T08:41:43.803 に答える
0

JasonCocoによる最初のコメントは、この問題に対して私が見つけた最良の解決策です。

于 2012-10-26T17:46:01.893 に答える