iPadのUIInterfaceOrientationを決定する 質問する

iPadのUIInterfaceOrientationを決定する 質問する

この場合、向きを指定する必要はなく、向きを検出すればいいのですが、問題があります。縦向きでのみ機能する条件付きコードがあり、デバイスが横向きの場合は別の操作を行う必要があります。deviceOrientation は必ずしも interfaceOrientation と同じではないため、縦向きモードをテストする方法が思いつきません。

Google で見つけたチュートリアルのほとんどは、強制的に横向きにしたり、何らかの回転を行ったりする方法です。私がやりたいのは、方向が何であるかを判断することだけです。これが私のコードですが、うまくいきません。

-(void)viewDidLoad {
    [super viewDidLoad];
    //currentOrientation is declared as UIInterfaceOrientation currentOrientation
    currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"%@",currentOrientation);  // == NULL
}

interfaceOrientation の値を決定し、条件付きでプログラムする必要があります。ご協力ありがとうございます。

ベストアンサー1

interfaceOrientationクラスのプロパティを認識していますかUIViewController?

- (void) viewDidLoad {
    [super viewDidLoad];
    BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
    // now do whatever you need
}

それとも、[[UIDevice currentDevice] orientation]?

おすすめ記事