1

我正在创建一个示例空应用程序并添加 UIViewController 类,

以下是 App delgate 中的代码

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

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

[self.window setRootViewController:navController];

现在我正在旋转应用程序,但在 UPsidedown 方向导航栏没有旋转我正在附加屏幕截图

在此处输入图像描述

然后在 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)并检查目标中的方向 在此处输入图像描述

3) 将类从UINavigationController更改为我在 IB 中的 XIB 中的CustomViewController

4)重置模拟器并运行代码,我想你的问题会解决的。

于 2013-08-30T07:29:35.177 回答
0

我认为你需要使用

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return TRUE;
}

而不是 shouldAutorotate

于 2013-08-30T07:25:15.990 回答
0

Supported interface orientations在 Xcode 上将Upside Down 按钮设置为 ON

http://www.appcoda.com/ios-game-tutorial-maze-part-1/

于 2013-08-30T07:31:02.580 回答
0

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

[self.window setRootViewController:viewController];`

从 appdelegate 中删除导航栏,然后检查

于 2013-12-12T09:46:18.597 回答