iOS6中的颠倒方向问题

时间:2013-08-30 07:17:37

标签: objective-c ios6 uiinterfaceorientation

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

以下是App delgate中的代码

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

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

[self.window setRootViewController:navController];

现在我正在旋转App但是在UPsidedown Orientation导航栏中没有旋转我附加了一个屏幕截图

enter image description here

然后在App委托中添加了下方法

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


    return UIInterfaceOrientationMaskAll;
}

在课程中我添加了以下方法

-(BOOL)shouldAutorotate
{
    return YES;
}

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

在摘要中,我已经激活了所有方向,任何人都可以告诉我解决方案

4 个答案:

答案 0 :(得分: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 enter image description here

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

4)重置模拟器并运行代码,我认为你的问题将得到解决。

答案 1 :(得分:0)

我认为你需要使用

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

而不是shouldAutorotate

答案 2 :(得分:0)

在Xcode上的Supported interface orientations中将倒置按钮设为ON

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

答案 3 :(得分:0)

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

[self.window setRootViewController:viewController];`

从appdelegate中删除navigatioan栏,然后检查