iOS 5 アプリを iOS 6 に更新する必要があり、もちろんインターフェイスの向きの問題に遭遇しました。私は今、物事が変わったことをすでに知っており、何が変わったのかさえ知っていますが、それでも自分でそれを管理することはできないようです.
私のアプリは、ナビゲーションコントローラーにプッシュされるいくつかのビューコントローラーで構成されています。縦向きにする必要がある1つを除いて、すべてのビューコントローラーは横向きにする必要があります。iOS 5 ではすべて正常に動作していましたが、ポートレート モードの 1 つのコントローラーがランドスケープ モードでも表示され、もちろん歪みます。
私の iOS 5 コードは次のようになりました。
ランドスケープモードのViewcontroller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
縦向きモードのViewcontroller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);
}
実装した iOS 6 の変更点を知った今、
AppDelegate: (plist のように、すべての方向を許可します)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
ランドスケープモードのViewcontroller: (向きをランドスケープモードに制限)
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
縦向きモードのViewcontroller: (向きを縦向きモードに制限)
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
- (BOOL)shouldAutorotate {
return YES;
}
私の理解では、これは機能するはずですが、実際には以前よりも機能が低下しています。まず、ランドスケープ モードのビュー コントローラーはランドスケープ モードのままではなく、すべての方向に自由に回転します。もちろん、これは私が望んでいたことではありません。次に、ポートレート モードのビューコントローラーがクラッシュします。
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
いくつかの試行錯誤の後、plistファイル/ appdelegateを介して、すべてのコントローラーをランドスケープモードにロックすることしかできないようです。これにより、もちろんポートレートモードコントローラーもランドスケープモードに強制されます。一方、縦向きモードのコントローラーを適切な向きにすることはできますが、これにより、横向きモードのコントローラーも縦向きモードに回転します。私は両方を機能させることができないようです。
何か案は?