2011-01-30 70 views
2

我是StackOverflow的新手,也是Objective-C的新手。啓動方向不對

我已經試過了幾個星期,現在找到了一些能夠給我提示做些什麼的東西,但是我似乎無法通過這個問題來解決問題。它感覺應該很簡單,但...

我遇到了「rootView」控制器旋轉的問題。它應該顯示在橫向上(在我決定使用導航控制器之前它是這麼做的)。模擬器以正確的方向顯示,但它已經加載了旋轉90度左右的視圖,以便文本從底部到頂部,側面讀取,因此您必須將頭部向左旋轉。視圖的最左邊部分是可見的,但視圖的其餘部分在屏幕的頂部運行。這是一個大型的程序(我發現,一般來說,使用objective-c,但是儘管如此......),但是這裏是我認爲重要的代碼區域的要點:

在appDelegate中,在實施

// .h file: 
UIWindow *window; 
wordHelper3ViewController *viewController; 
UINavigationController *navigationController; 

然後:我創建了一個窗口,我的RootViewController的,和navcontroller

//.m file 
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    // Hide status bar 
    application.statusBarHidden = YES; 
     // --- Add the view controller's view to the window and display. 
    [window addSubview:viewController.view]; 
    [window addSubview:navigationController.view]; 
    [window makeKeyAndVisible]; 
    return YES; 
} 

然後我釋放所有的這些中的dealloc。

在我的根認爲,我這樣做:

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     return YES; 
    } else { 
     return NO; 
    } 
} 

我實現以下,看看發生了什麼事,而我立即啓動獲取日誌消息:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     NSLog(@"didRotate..."); 
    } 
} 

除此之外,我不認爲我在我的代碼中會做任何影響視圖的事情。所以現在,在InterfaceBuilder上:

在屬性檢查器中,根視圖和導航控制器都將方向設置爲橫向。對於rootView,在引用插座下,「視圖」被設置爲文件的所有者。我也有一個附加到視圖的動作(touchUpInside) - 我將它的類更改爲UIButton,因爲當用戶在後臺的任何地方點擊時我想要resignFirstResponder。

對於navigationController,在Referencing outlets下,它顯示從navigationController到我的appDelegate的連接。

在主窗口xib中,導航控制器顯示在列表中,並且視圖控制器顯示爲其子視圖。

視圖控制器也在主窗口的對象列表中顯示。

唯一突出給我的是,當我雙擊窗口對象時,IT在縱向模式下可視化顯示。

有沒有人有任何想法?

+0

你介意張貼的截圖取向問題,你的描述有點不清楚。 – Moshe 2011-01-30 18:02:25

+0

的截圖工作... – pereirap 2011-01-30 22:03:30

+0

的截圖張貼我的谷歌文檔頁面上 - 這裏的鏈接: https://docs.google.com/document/d/1kZMPTsqVT6yAdxCa1HPXu0jhZnDa4QOsJ3p9_wqYs5Q/edit?hl=en&authkey=CJf58PEG – pereirap 2011-01-30 22:10:47

回答

1

我認爲你的問題是你將導航控制器作爲子視圖添加到窗口,並且方向通知只發送到「窗口」中的第一個子視圖。

試試這個。


//.m file 
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    // Hide status bar 
    application.statusBarHidden = YES; 
     // --- Add the view controller's view to the window and display. 
    [window addSubview:viewController.view]; 
    [viewController.view addSubview:navigationController.view]; 
    [window makeKeyAndVisible]; 
    return YES; 
} 
 

其煩,但我只在「窗口」每有一個子視圖,然後控制一切通過一個子視圖解決(在這種情況下的viewController)

13

如果您希望啓動方向與初始肖像模式不同,您需要編輯您的info.plist文件。爲「初始界面方向」添加條目並設置所需的值。

以下是截圖:

enter image description here

如果你想旋轉一個UINavigationController,將採取更多的工作。請參閱this similar question for更多信息。

0

原諒我,如果我誤解,但不應該在該

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     return YES; 
    } else { 
     return NO; 
    } 
} 

真的是這樣

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
}