8

iOS 6.0 でいくつかのアプリ ビュー コントローラーを回転させないようにしたい。これは、iOS 6 で回転を可能にするために私が行ったことです。

1.) application:didFinishLaunchingWithOptions で Windows の rootviewController を設定します。

self.window.rootViewController = self.tabBarController;

2.) ターゲット (XCode) で「サポートされているインターフェイスの向き」を設定して、すべての向きを使用できるようにします。

3.) 新しい iOS 6.0 回転機能を実装しました

- (BOOL) shouldAutorotate {

    return YES;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

4.) 何らかの理由で、UINavigationController をサブクラス化し、これらの新しい機能も実装し、元のナビゲーション コントローラーの代わりにこの新しいナビゲーション コントローラーを使用しました。

これまでのところ、すべてが正常に機能し、すべてのビューコントローラーがすべての向きに回転できるようになりました. 今、私はいくつかのviewControllerを回転させず、縦向きにとどめたいと思っています。しかし、このような特定のビューコントローラーで新しい回転メソッドを設定すると、すべての向きに回転します:

- (BOOL) shouldAutorotate {

    return NO;
}


-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}

また、上記のようにナビゲーション コントローラーの回転機能を設定しても、何も変わりません。(すべてのビューコントローラーはあらゆる方向に回転できます)

私は何を間違っていますか?

編集:

また、優先する Interfaceorientation を設定しても何も変わりません。

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationMaskPortrait;
}
4

3 に答える 3

11

すべてのナビゲーション コントローラーがトップ ビュー コントローラーを尊重するようにしたい場合は、カテゴリを使用できます。サブクラス化よりも簡単だと思いました。

@implementation UINavigationController (Rotation_IOS6)

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

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

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

@end
于 2012-09-25T17:24:59.090 に答える
0

自動回転をサポートするには、 UITabBarController のカテゴリを作成する必要があります

.h ファイルのコードは

@interface UITabBarController (autoRotate)<UITabBarControllerDelegate>

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

@end

.mファイルのコードは

-(BOOL)shouldAutorotate {

    AppDelegate *delegate= (AppDelegate*)[[UIApplication sharedApplication]delegate];
    return [delegate.tabBarController.selectedViewController shouldAutorotate];
}


- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

注: AppDelegate の名前は、プロジェクトの AppDelegate ファイル名に変更されます。

于 2012-11-29T05:37:02.383 に答える
0

これは私のために働く:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}
于 2012-09-21T08:10:57.040 に答える