1

アプリにはアプリ デリゲートとビュー コントローラーが 1 つしかありません。アプリは、縦向きと横向きの両方のモードで動作します。私のView ControllerのviewWillAppearメソッドでは、次のコードを使用してデバイスの向きを取得しています:

UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation])

初めてアプリケーションを実行すると、デバイスが縦向きの場合でも、結果が横向きになります。なぜそうなのか。どうすればこれを解決できますか?

4

3 に答える 3

5

currentDevice.orientation で多くの問題が発生しました これを試してください:

UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])
于 2011-10-04T16:46:40.167 に答える
0
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;


if (UIDeviceOrientationIsLandscape(deviceOrientation)
{
   //LandscapeView
}
else
{
   //PortraitView
}
于 2011-10-04T16:35:22.597 に答える
0

UIDeviceのドキュメントから:

このプロパティの値は、beginGeneratingDeviceOrientationNotifications を呼び出して方向通知が有効になっていない限り、常に 0 を返します。

「orientation」によって返される実際の値を見ると、「UIDeviceOrientationUnknown」であることがわかります。

于 2011-10-04T16:46:55.777 に答える