5

アプリを iOS6 標準に更新すると、縦向き/横向きがなくなります。Xcode 3 でビルドしていたとき、Ir は完全に機能しました。しかし、最新の Xcode と最新の SDK を使用すると、回転がなくなり、常に縦向きモードになります。「サポートされているインターフェイスの向き」に何を入れても。以前に回転を取得するために使用したコードは、まったく効果がないようです。私はこれらの行を持っていました。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    switch (toInterfaceOrientation) {
        case UIInterfaceOrientationPortrait:
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            return YES;
        default:
            return NO;
    }
}

どのように変更すればよいですか? また、再び動作させるには何を変更すればよいですか?

4

3 に答える 3

17

まず、AppDelegateでこれを記述します。これは非常に重要です

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return (UIInterfaceOrientationMaskAll);
}

次に、PORTRAITモードのみが必要なUIViewControllersの場合、これらの関数を記述します。

- (BOOL)shouldAutorotate
{
     return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
     return (UIInterfaceOrientationMaskPortrait);
}

LANDSCAPEも必要とするUIViewControllersの場合、マスキングをAllに変更します。

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAllButUpsideDown);
    //OR return (UIInterfaceOrientationMaskAll);
}

ここで、向きが変更されたときに変更を加えたい場合は、この関数を使用します。

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

}

編集 :

UIViewControllerがどのコントローラーに埋め込まれているかによって大きく異なります。

たとえば、その内部がUINavigationControllerの場合、このような方向付けメソッドをオーバーライドするには、そのUINavigationControllerをサブクラス化する必要がある場合があります。

サブクラス化されたUINavigationController(階層の最上位のviewcontrollerが方向を制御します)は、self.window.rootViewControllerとして設定しました。

 - (BOOL)shouldAutorotate
 {
     return self.topViewController.shouldAutorotate;
 }
 - (NSUInteger)supportedInterfaceOrientations
 {
     return self.topViewController.supportedInterfaceOrientations;
 }

iOS 6以降、UINavigationControllerはUIVIewControllersに方向のサポートを要求しません。したがって、それをサブクラス化する必要があります。

于 2012-10-04T13:33:31.800 に答える
6

主にiOS6でポートレートであるアプリで1つ以上のランドスケープコントローラーをサポートする方法:

1)AppDelegateで

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        UINavigationController* ns = (UINavigationController*)self.window.rootViewController;
        if (ns) {
            UIViewController* vc = [ns visibleViewController];
//by this UIViewController that needs landscape is identified
            if ([vc respondsToSelector:@selector(needIos6Landscape)])
                return [vc supportedInterfaceOrientations];

        }
        return UIInterfaceOrientationMaskPortrait; //return default value
    }

2)横向き(または縦向き+横向きなど)が必要なUIViewコントローラーの場合:

//flag method
-(void)needIos6Landscape {
}
- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

3)コントローラーから戻ることができるコントローラーでは、横向きに回転できます。これは重要です。それ以外の場合は、横向きのVCから戻っても横向きのままです。

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

4)(おそらく必要ではありませんが、確かに..)-使用しているサブクラスのナビゲーションコントローラー、および追加:

- (BOOL)shouldAutorotate
{
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    UIViewController* vc = [self visibleViewController];
    if (vc) {
        if ([vc respondsToSelector:@selector(needIos6Landscape)]) {
             return [vc supportedInterfaceOrientations];
        }
    }
    return UIInterfaceOrientationMaskPortrait;
}

重要なステップは、アプリからコントローラーのみの向きを要求することです。コントローラー間の移行中に、しばらくの間、ルートとしていくつかのシステムコントローラーがあり、誤った値を返すためです(これは、見つけるのに2時間かかりました、それが理由でした動作していませんでした)。

于 2012-12-14T15:46:44.787 に答える
1

あなたの問題が似ているかどうかはわかりませんが、私にとっては、ステータスバーが正しい向き (横向き) で、UIViewController描写されていました。アプリケーション デリゲートapplication:didFinishLaunchingWithOptionsの次の行を変更しました。

//[window addSubview:navigationController.view];

self.window.rootViewController = navigationController;

アップル=>これを見つけるのに1日半かかり、多額のお金がかかりました!!!

于 2012-10-19T13:11:41.167 に答える