16

ああ!私はiOS5でタブバーの回転の問題を最終的に解決しましたが、iOS6とxcodeは問題を解決したようです...これが私が持っているものです:

ターゲットアプリの概要は次のとおりです。サポートされているインターフェースの向き-Portraint、Landscape Left、Landscape Right

アプリのすべてのシングルビューには、次の方法があります。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    return ((interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) &&
            (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) &&
            (interfaceOrientation != UIInterfaceOrientationLandscapeRight));
} else {
    return YES;
}
}

- (BOOL)shouldAutorotate
{
NSLog(@"am I called1?");
return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
   NSLog(@"am I called?");
   return UIInterfaceOrientationMaskPortrait;
}

タブバーの一部ではないビューでは、回転がブロックされます。タブバーのすべてのビュー(5つあります)では、アプリはShouldAutorotateを呼び出さないため、回転します。サポートされているInterfaceOrientationsは、ビューが読み込まれるときに1回呼び出されるようですが、NSLogを取得するため、ビューを切り替えると表示されるときは呼び出されませんが、MaskPortrait設定を無視しているようです。

回転する必要のある単一のビデオプレーヤービューがあるため、ターゲットでランドスケープを有効のままにしておく必要があります(そうすることで問題ありません)

これはiOS6のタブバーのバグですか?ビューの回転を別の方法で無効にする必要がありますか?shouldautorotatetointerfaceorientationはiOS5でうまく機能しました

私はしばらくそれをやってきた

ありがとう、ザック

4

8 に答える 8

36

ザック、私はこれと同じ問題に遭遇しました。これは、viewControllerがTabBar ControllerまたはUINavigationController内に埋め込まれていて、これらのメソッドの呼び出しが通常のView(iOS6で変更)ではなくそれらの内部で行われているためです。

この問題が発生したのは、さまざまなビュー(サインアッププロセス、ログインなど)へのナビゲーションを備えたすべてのモーダルビューでUINavigationController内に埋め込まれたviewControllerを提示していたためです。

私の簡単な修正は、これら2つのメソッドを含むUINavigationControllerのCATEGORYを作成することでした。モーダルビューを回転させたくないので、とにかくNOを返すshouldAutorotateがあります。あなたの修正はこれほど簡単かもしれません、それを試してみてください。それが役に立てば幸い。

カテゴリを作成してautoRotateという名前を付け、UINavigationControllerオプションを選択しました。M+Hファイルは以下のとおりです。

#import "UINavigationController+autoRotate.h"

@implementation UINavigationController (autoRotate)

-(BOOL)shouldAutorotate {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

@end

...およびカテゴリ.h:

#import <UIKit/UIKit.h>

@interface UINavigationController (autoRotate)

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

@end
于 2012-09-21T07:37:52.623 に答える
11

私のようにタブバーがある場合は、デリゲート.mファイルに以下を追加するだけです。

#import "AppDelegate.h"

//UITabBarController category to set the view rotations for ios 6
@implementation UITabBarController (Background)

-(BOOL)shouldAutorotate
{
    //I don't want to support auto rotate, but you can return any value you want here
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    //I want to only support portrait mode
    return UIInterfaceOrientationMaskPortrait;
}

@end


/////here starts the implementation of the app delegate which is gonna be whatever you currently have on your .m delegate

@implementation AppDelegate

// delegate methods and other stuff

@end
于 2012-10-31T22:05:43.670 に答える
7

また、いくつかのビューを回転させる必要があり、他のビューにはいくつかのナビゲーションコントローラーが必要ないという問題もありました。これを行うには、NavigationControllerにViewControllerを調べるように指示します。これが私がしたことです。

RootNavigationControllerというUINavigationControllerクラスを作成し、そのクラスをストーリーボードのナビゲーションコントローラーのカスタムクラスとして指定しました。RootNavigationController.mに、次のメソッドを追加しました。

- (BOOL)shouldAutorotate {

    return [self.visibleViewController shouldAutorotate];
}

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

各ViewController.mファイルに、次のメソッドも追加しました。

- (BOOL)shouldAutorotate {
    //return yes or no
}

- (NSUInteger)supportedInterfaceOrientations{
    //return supported orientation masks
}

これを行うと、ViewControllerで各ビューの向きを設定できます。

とにかく私のために働いた…</p>

于 2012-09-25T21:33:54.130 に答える
7

私の状況は次のとおりです。

  • UITabBarControllerには2つのアイテムがあります:2つのナビゲーションコントローラー
  • UINavigationController1 withRootView:ViewController1
  • UINavigationController2 withRootView:ViewController2。
  • ここで、ViewController1セットshouldAutorotate:NO/maskPortraitとViewController2セットshouldAutorotate/MaskAllが必要です。

だから私の実装:次のようなUITabBarControllerカテゴリとUINavigationCntrollerカテゴリを作成します

UITabBarController + autoRotate.h

@interface UITabBarController (autoRotate)

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

@end

UITabBarController + autoRotate.m

#import "UITabBarController+autoRotate.h"

@implementation UITabBarController (autoRotate)

- (BOOL)shouldAutorotate {
    return [self.selectedViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
    return [self.selectedViewController supportedInterfaceOrientations];
}

@end

UINavigationController + autoRotate.h

@interface UINavigationController (autoRotate)

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

@end

UINavigationController + autoRotate.m

@implementation UINavigationController (autoRotate)

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

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

@end

UIViewController1.m

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

UIViewController2.m

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

それは魅力のように機能しました!

于 2013-06-18T06:22:16.020 に答える
0

私の場合、UITabBarController内にナビゲーションコントローラーが埋め込まれていて、機能したのはKunaniのようなカテゴリを作成することでしたが、UINavigationControllerの代わりにUITabBarControllerを拡張しました。それは魅力のように機能しました:)

#import "UINavigationController+autoRotate.h"

@implementation UINavigationController (autoRotate)

-(BOOL)shouldAutorotate {
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

@end

そして.hファイル:

#import <UIKit/UIKit.h>

@interface UINavigationController (autoRotate)

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

@end
于 2013-06-13T21:52:58.527 に答える
0

これはSwiftでそれを行います

extension UITabBarController {
    public override func shouldAutorotate() -> Bool {
        if let selected = self.selectedViewController {
            return selected.shouldAutorotate()
        } else {
            return false
        }
    }

    public override func supportedInterfaceOrientations() -> Int {
        if let selected = self.selectedViewController {
            return selected.supportedInterfaceOrientations()
        } else {
            return Int(UIInterfaceOrientationMask.Portrait.rawValue)
        }
    }
}

extension UINavigationController {
    public override func shouldAutorotate() -> Bool {
        return self.visibleViewController.shouldAutorotate()
    }

    public override func supportedInterfaceOrientations() -> Int {
        return self.visibleViewController.supportedInterfaceOrientations()
    }
}
于 2014-12-11T11:48:02.830 に答える
0

https://stackoverflow.com/a/30632505/2298002

この状況を処理する場合、特に特定のView Controllerのみの向きを維持し、アプリの他の部分に影響を与えない場合は、あいまいな結果や予期しない結果が多数発生します。このアルゴリズムは私にすべてを渡すようです

https://stackoverflow.com/a/30632505/2298002

于 2015-06-03T23:28:12.250 に答える
-1

UIViewController1.m以前のオリエンテーションステータスが再構築されることを確認するために、これをに追加する必要があります。

 (void)viewDidAppear:(BOOL)animated 
{

    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") 
    withObject:(id)UIInterfaceOrientationPortrait];
}

完全!

于 2013-06-18T07:36:41.423 に答える