2012-01-12 37 views
0

因此,在我的應用程序中,我有一個導航堆棧,用戶可以通過多種viewControllers進行導航。有些視圖支持多個方向,而其中一個視圖不支持。所以我的問題是,我如何強制一個特定的UIViewController只顯示在一個方向。我需要這個工作,當第一次加載視圖時,以及另一個視圖彈出時,這個視圖再次可見。由於強制UIViewController加載某個方向

我實現了這個兩種方法來控制的觀點旋轉:

-(void)orientationDidChange:(NSNotification *)notification 
-(BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

感謝

+0

你可以發佈你的上述委託方法的實現嗎? – 2012-01-12 04:17:45

+0

這個問題已經被問過很多次:http://stackoverflow.com/questions/3538796/how-to-force-horizo​​ntal-orientation。簡而言之,重寫該方法並更改返回值以僅支持所需的方向。 – aqua 2012-01-12 04:19:22

+0

我試過之前我問 - 不工作 – Andrew 2012-01-16 08:42:54

回答

1
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
0

答:shouldAutoRotateToInterfaceOrientation方法UIViewController類。如果UIView支持方向,則此函數返回YES。如果您只有return YESlandscape orientation,那麼只要您加載該視圖,iPhone/iPad就會自動進入該方位。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscape); 
}