0

このコードを使用して、iOS アプリケーションのランドスケープ モードをロックしています。

#pragma mark Orientation handling

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}

iPhoneでは正常に動作していますが、iPadでは正しく動作していません。ランドスケープ モードをロックしません。

これに関するガイダンスが必要です。

4

4 に答える 4

1

このコードは正しくありません:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}

AUIInterfaceOrientationは ではありませんUIInterfaceOrientationMask。代わりに次のようにしてみてください。

return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);

そうは言っても、アプリケーションを横向きモードにロックしようとしている場合、ここには他にも複数の問題があります。たとえば、supportedInterfaceOrientationsリストは縦向きモードのみで、横向きモードではありません!

于 2013-05-06T16:45:24.637 に答える
0

iOS 6 では、次を使用します。

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

NavigationController がある場合は、メソッドをカテゴリに追加できます。

于 2013-05-06T17:50:39.947 に答える
0

コメントにあるように、理想的には概要タブに設定するだけです。本当にコードでこれを行いたい場合は、AppDelegate クラスで rootViewController として設定したものでのみ利用できます。

于 2013-05-06T16:02:39.127 に答える