1

サンプルの空のアプリケーションを作成し、UIViewController クラスを追加しました。

以下はアプリデリゲートのコードです

TestViewController* viewController  = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];

UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:viewController];

[self.window setRootViewController:navController];

今、私はアプリを回転させていますが、UPsidedown Orientation ナビゲーション バーが回転していません。スクリーン ショットを添付しています。

ここに画像の説明を入力

次に、 App デリゲートに以下のメソッドを追加しました

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{


    return UIInterfaceOrientationMaskAll;
}

クラスでは、次のメソッドを追加しました

-(BOOL)shouldAutorotate
{
    return YES;
}

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

概要で、私はすべてのオリエンテーションを有効にしました。誰でも解決策を教えてくれます

4

4 に答える 4

1

1) UINavigationController クラスのカテゴリを作成し、これらのメソッドを定義しました

CustomViewController.h 内

#import <UIKit/UIKit.h>

@interface CustomViewController : UINavigationController

@end

CustomViewController.m 内

#import "CustomViewController.h"

@interface CustomViewController ()

@end

@implementation CustomViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL) shouldAutorotate{
    return YES;
}

-(NSUInteger) supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskAll;
}

および AppDelgate.m ファイル

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

    CustomViewController *navController = [[CustomViewController alloc] initWithRootViewController:self.viewController];
    // Override point for customization after application launch.

    self.window.rootViewController = navController;
    [self.window makeKeyAndVisible];
    return YES;
}

2) そして、Orientation In Target をチェックします ここに画像の説明を入力

3) IB の XIB でクラスをUINavigationControllerからCustomViewControllerに変更します。

4) シミュレーターをリセットしてコードを実行すると、問題は解決すると思います。

于 2013-08-30T07:29:35.177 に答える