4

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を介して、すべてのコントローラーをランドスケープモードにロックすることしかできないようです。これにより、もちろんポートレートモードコントローラーもランドスケープモードに強制されます。一方、縦向きモードのコントローラーを適切な向きにすることはできますが、これにより、横向きモードのコントローラーも縦向きモードに回転します。私は両方を機能させることができないようです。

何か案は?

4

2 に答える 2

7

わかりました私はそれを修正しました。

UINavigationController のカテゴリを作成しました

@implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}

@end

ビューコントローラーの値をナビゲーションコントローラーに転送するには...

また、最初のものは非推奨になったため、presentModalViewController を presentViewController に置き換える必要がありました。

ところで、はい、私の appdelegate にタイプミスがあります...これは正しいです。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;
}
于 2012-10-11T10:50:04.077 に答える
0

UIInterfaceOrientationMaskLandscapeLeft で appdelegate LandscapeRight に 2 回書き込まれていることを確認しました

rootViewControllers のみが見つかりました - (BOOL)shouldAutorotate; 呼ばれる。ここで、rootViewController は NavigationController です。そして、プッシュされたviewControllerの場合、これは呼び出されないため、プッシュされたビューの方向サポートをnavControllersメソッドのみから決定する必要があります。私のnavControllersがviewController
Override UINavigationControllersメソッドをプッシュしたために、以下がうまくいきました

- (BOOL)shouldAutorotate;
- (NSUInteger) supportedInterfaceOrientations;

コードはあなたにとってこのようなものになります

@implementaion UINavigationController(Rotation)

- (BOOL)shouldAutorotate
{
return YES;
}

- (NSUInteger) supportedInterfaceOrientations
{
    NSArray *viewsArray = [self viewController]//stack of pushed controller

    NSUInteger orientationToReturn = assignAllMask;

    for(UIViewController *temp in  viewsArray)
    {
        if([temp isKindOfClass:MyOnlyLandscapeViewController] == YES )
        {
            orientationToReturn = assignLandscapeMask;
            break;
        }
        else if([temp isKindOfClass:MyOnlyPortraitViewController] == YES )
        {
            orientationToReturn = assignPortraitMask;
            break;
        }
    }

    return orientationToReturn;
}

@end
于 2012-10-10T19:45:32.533 に答える