2013-03-14 60 views
3

最初的UINavigationControllerNavigator)的子類是根控制器和它支持所有取向。 子類覆蓋supportedInterfaceOrientations,並提供屬性來設置支持什麼方向。如何檢測設備方向與界面方向不同?

Navigator的導航堆棧(UITableViewContreller的子類)的根視圖控制器控制支持的方向(取決於哪個視圖控制器位於堆棧頂部)。它設置在didSelectRowAtIndexPath覆蓋Navigator S取向性。

如果在設備處於不同方向時進行轉換(因爲當前視圖不支持它並且這不是一種假定的交互方式),並且新視圖支持該設備方向,所以視圖保持不同於設備方向。 然後人們需要旋轉設備並將其移回到正確的方向。

這是如果有人出於某種原因將持有的景觀模式的設備在聯繫人應用程序,但突然它的一個子視圖將支持橫向和不爲縱向和橫向然後旋轉裝置自動旋轉。問題是如何實現它?

回答

1

在每個方法使用此:

if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
    ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) 
{  

} 
else 
{ 

} 

或檢查[[UIScreen mainScreen] bounds]

+0

基於視圖框的大小,你可以識別橫向模式或縱向模式 – 2013-03-14 13:39:53

+0

我的意思是,你需要在每一個函數來檢查幀大小的 – 2013-03-14 13:46:32

0

我覺得這是要你想要的。

要獲得設備的方向:

[[UIDevice currentDevice] orientation]; 

要得到的意見電流方向顯示:

[UIApplication sharedApplication].statusBarOrientation; 
0

添加這個方法將你的UINavigationController子類:

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
     return; 

    if ([UIViewController respondsToSelector:@selector(attemptRotationToDeviceOrientation)]) { 
     //present/dismiss viewcontroller in order to activate rotating. 
     UIViewController *mVC = [[UIViewController alloc] init]; 
     [self presentModalViewController:mVC animated:NO]; 
     [self dismissModalViewControllerAnimated:NO]; 
    } 
} 

(在SF上找到它,但無法找到該問題的鏈接)