1

ポートレートモードでアプリを表示することに成功しました。問題は、横向きで見ると適切ではないようです。このコードを実装しました。

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
    return interfaceOrientation=UIInterfaceOrientationLandscapeLeft;
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
    return interfaceOrientation=UIInterfaceOrientationLandscapeRight;
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
   return interfaceOrientation=UIInterfaceOrientationPortrait;
}   

何か特別なことをする必要がありますか?このコードは私に役立ちますか?

4

1 に答える 1

1

shouldAutorotateToInterfaceOrientation:考えられるすべての向きをサポートする場合は、 の実装を次のように変更します。

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

UIInterfaceOrientationLandscapeLeftUIInterfaceOrientationLandscapeRightおよびのみをサポートする場合はUIInterfaceOrientationPortrait、コードを次のように変更します。

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

[UIApplication sharedApplication].statusBarOrientationすでにパラメータとして持っているため、新しい向きを探す必要はありません。


デバイスが回転したときにビューの要素を再配置したい場合は、それらのautoresizingMaskプロパティを使用する必要があります。別のオプションは、メソッドを実装することwillRotateToInterfaceOrientationです。

Size InspectorautoresizingMaskの Interface Builder のビューの要素を変更できます。必要な結果が得られるまで、さまざまな組み合わせを試してみてください。

ここに画像の説明を入力

最後に、ビューが複雑であるか、方向ごとに根本​​的に異なる場合、最適なオプションは 2 つの xib ファイルを使用することです。1 つは縦向き用、もう 1 つは横向き用です。

于 2012-03-12T13:11:45.117 に答える