2

向きの変更をサポートし、それに応じて回転するアプリがあります。イベント UIApplicationWillChangeStatusBarOrientationNotification をリッスンします。このアプリの読み込み中に、現在の向きに基づいて、いくつかのビューを追加してアプリに設定します。

iOS 6 では、これは正常に機能し、アプリは適切に応答して回転するため、ユーザーは横向きモードと縦向きモードの両方でロードでき、コードは正常に機能します。

iOS 5 では、縦向きモードでアプリをロードすると、アプリは正常に動作し、縦向きモードでのロードが完了し、UI の位置合わせとサイズが調整されると、横向きまたは縦向きへの他の向きの変更に応答します。私が抱えている問題は次のとおりです。iOS 5をランドスケープモードでロードし、iOS 5を搭載したデバイスを物理的に平らな面に置いてランドスケープを確保しているときに、ランドスケープからポートレートに移動するOrientationNotificationを取得します(デバイスはそうではありませんでした)変化する )。

したがって、同じ実験で別のデバイス iOS 6 が正しく読み込まれ、発生しなかった回転変化の奇妙なイベントは発生しませんが、iOS 5 では発生します!!

何か案は?

両方の iOS の向きをサポートしています

- (BOOL)shouldAutorotate {
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:
                                   (UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait ||
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
4

1 に答える 1

2

iOS 5 は、実際には物理的な向き (つまり、平らな上下) がなく、iOS 6 がそうでない場合、物事は縦長であるべきだと信じているようです。重要な場合に表示する向きを決定するために、利用可能な場合は実際のデバイスの向きを使用し、デバイスが平らな場合はステータス バーの向きを使用します。例えば:

// Get a useful screen orientation.
// If the device is physically in portrait or landscape then
// that is the orientation.
// If it is not, then it is probably flat on a table and use
// the orientation of the status bar which should be set to
// the last physical orientation.
//
// screen Orientation
//------------------------------------------------------------
+ (UIDeviceOrientation) screenOrientation {
   UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   if (orientation!=UIInterfaceOrientationPortrait
       && orientation!=UIInterfaceOrientationPortraitUpsideDown
       && orientation!=UIInterfaceOrientationLandscapeLeft
       && orientation != UIInterfaceOrientationLandscapeRight) {
       // Not known at this time.  Use the status bar orientation
       orientation = [[UIApplication sharedApplication] statusBarOrientation];
   }
    return orientation;
}

直接役立つかどうかはわかりませんが、おそらく通知ハンドラーで、実際のステータスバーの向きを確認できます。または、通知のタイミングとステータス バーの向きの変更によって、それがうまくいかない場合もあります。

于 2013-03-01T17:37:25.507 に答える