2011-08-10 135 views
0

我正在創建一個具有橫向正確方向的應用程序。爲此,我在info.plist文件中設置了Initial interface orientation屬性。然後在我處理的每個視圖中Ipad方向不能正常工作

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

它在模擬器中正常工作,但在設備中其行爲不同。 我的第一個看法是正確的。有popover顯示另一個肖像模式的視圖。不過我的狀態欄是在園林的權利..

從一個視圖導航到我使用的另一種觀點..

self.window.rootViewController = self.myNav; 

我有多個導航控制器及添加使用上這些代碼。 我沒有得到什麼問題。

任何幫助將不勝感激。

EDIT:我用了

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

我從來沒有這個問題在模擬器,但設備,而不是每次都得到這個。我也使用了Supported interface orientations (iPad),併爲item0設置了Landscape (right home button)的值。

在此先感謝

回答

1

您有多少個視圖(或viewControllers)?您可能需要在所有這些視圖中實現此方向邏輯?

+0

我這個已經做... 我使用後試圖'[的UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]' 我從來沒有這個問題在模擬器,但得到這個裝置中,而不是每次都.. –

3

您需要將頂視圖(在所有xib文件中)的「Simulated Metrics> Orientation」屬性設置爲「Landscape」。默認是肖像。

這個問題在這裏得到了很好的回答 - Landscape Mode ONLY for iPhone or iPad

我也有一個像你的應用程序只支持UIInterfaceOrientationLandscapeRight。到目前爲止,我還沒有遇到任何方向問題。窗口下只有一個UIViewController。這個UIViewController有它自己的UITabBar,我用它來改變頁面。所以,我們換頁的方式不同。我使用窗口的rootViewController屬性來設置我的UIViewController,就像你一樣,但我只有一個。

此外,我從來不需要做任何事情,比如您包括的[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]調用。由於您只支持LandscapeRight方向,因此您不應該關心被通知的變化。

編輯

我創建了一個示例項目,我可以張貼如果必要的話,我想我可能知道你的問題。首先 - 你是否只遇到彈inside內的大小問題?如果是這樣,那麼我認爲定向不會把你扔掉,而是把彈出的東西本身扔掉。我的示例項目有3個視圖控制器。第一個通過更改窗口的rootViewController加載第二個。這工作得很好。第二個視圖控制器有一個按鈕來打開彈出窗口。這將顯示錯了,除非你設置視圖控制器上的contentSizeForPopover,如下圖所示:

- (IBAction) showVC3InPopover 
{ 
    UIViewController * vc3 = [[VC3 alloc] init]; 
    /** Set the contentSizeForViewInPopover property to determine how 
     large the view will be in the popover! You can do this in the 
     init method(s) of the view controller if you prefer, it's just 
     easy to do here */ 
    vc3.contentSizeForViewInPopover = vc3.view.frame.size; 
    [_popover release], _popover = nil; 
    _popover = [[UIPopoverController alloc] initWithContentViewController:vc3]; 
    [vc3 release]; 

    [_popover presentPopoverFromRect:_showPopoverButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
} 

看看這個修復您的問題。如果是這樣,還有其他方法可以控制彈出窗口大小,但這正是我通常所做的。但是,只要知道PopoverController忽略了您加載的視圖控制器中視圖的大小。

+0

我已經以橫向模式創建xib文件完成。第一個視圖運行良好。但是當我使用'[self.window setRootViewController:self.navHome]添加新視圖;'它在ios 4.2中遇到問題。 –

+0

我會做一個示例項目來嘗試一下。 – Sam

+0

轉換到新的視圖控制器在哪裏發生?防爆。 ViewController 1是否有一個提示加載ViewController 2的按鈕(或其他)?通常你會有一個UITabBar來更改視圖控制器頁面。 – Sam