天天看點

iOS 橫屏遇到的問題

IOS 6.0

XCODE 4.6.2

本人也是xib的初學者,按以下連接配接在ipad上做了一個練習,運作正常。

http://blog.csdn.net/totogo2010/article/details/7615495

但是當我想設定為橫屏時,做了如下設定:

1. Supported Interface Orientations

選擇了Landscape Left 和 Landscape Right

iOS 橫屏遇到的問題

2. root controller xib 檔案設定:

Simulated Metrics - Orientation: Landscape.

3. AppDelegate 添加代碼

AppDelegate.h: append IBOutlet

AppDelegate.m:

失敗1:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

...

    [[NSBundle mainBundle] loadNibNamed:@"GUNRootViewController" owner:self options:nil];

    [self.window addSubview:self.rootViewController.view];

失敗2:

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

    self.window.rootViewController = self.rootViewController;

成功:

    [[NSBundle mainBundle] loadNibNamed:@"GUNRootViewController" owner:self options:nil];

    self.window.rootViewController = self->rootViewController;

合理的解釋可以參考 http://www.apeth.com/iOSBook/ch19.html