2

我有一個標籤欄應用程序,其中包含兩個選項卡中的導航視圖。我希望1導航控制器中的1個視圖允許橫向視圖,但由於導航欄在標籤欄限制中,我現在必須允許我的應用中的每個視圖的橫向視圖使傾斜消息傳遞到我的應用程序,我不想要。限制包含UINavigationController的UITabBarController中的橫向視圖

我想也許是,不應該去風景的意見,可能有辦法: 防止視圖改變例如,每當設備變爲風景 或 時調用setOrientation:UIDeviceOrientationPortrait給出視圖不會改變的錯覺,例如,在旋轉的視圖上呈現模態肖像視圖

任何人都有任何他們想分享的想法或經驗嗎?這裏最好的方法是什麼? (我不想現在必須爲每個視圖設計一個橫向視圖,以便我可以爲1個視圖顯示縱向&橫向視圖)

回答

2

最近我必須處理同樣的問題,我的解決方案是如下:查看的的UIViewController內

要能夠旋轉添加一個通知處理器爲UIDeviceOrientationDidChangeNotification

-(void)viewDidLoad { 


[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(didRotateFromInterfaceOrientation) 
              name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

}

那麼當然你需要實現你的didRotateFromInterfaceOrientation方法。

該方法中你可以使用

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

我所做其次是評價我想視圖中顯示,基於取向

switch (orientation) { 
    case UIDeviceOrientationLandscapeLeft: 
     NSLog(@"UIDeviceOrientationLandscapeLeft"); 
     [self presentModalViewController:LandscapeView animated:YES]; 

     break; 
    case UIDeviceOrientationLandscapeRight: 
     NSLog(@"UIDeviceOrientationLandscapeRight"); 

     [self presentModalViewController:LandscapeView animated:YES]; 

     break; 
    case UIDeviceOrientationPortraitUpsideDown: 
     NSLog(@"UIDeviceOrientationPortraitUpsideDown"); 
     [LandScapeview dismissModalViewControllerAnimated:YES]; 

     break; 
    case UIDeviceOrientationPortrait: 
     NSLog(@"UIDeviceOrientationPortrait"); 
     [LandscapeView dismissModalViewControllerAnimated:YES]; 
     break; 

    case UIDeviceOrientationFaceUp: 
     NSLog(@"UIDeviceOrientationFaceUp"); 

     break; 

    case UIDeviceOrientationFaceDown: 
     NSLog(@"UIDeviceOrientationFaceDown"); 
     break; 

    default: 
     break; 
    } 
} 

我希望我能幫助當前方向一點點。

+0

哦,不要忘記刪除通知處理程序,如果視圖中消失... \t [NSNotificationCenter defaultCenter] removeObserver:自 \t \t \t \t \t \t \t \t \t \t \t \t \t名:@ 「UIDeviceOrientationDidChangeNotification」 \t \t \t \t \t \t \t \t \t \t \t \t object:nil]; – samsam 2010-05-06 07:29:31

+0

我只是想檢查一下,我明白了,我會留下所有其他的意見,因爲不支持風景&然後你的代碼將確保方向改變消息仍然可以收到的旋轉視圖控制器,我是否正確? – 2010-05-06 07:54:04

+0

是的,這是正確的。我有同樣的問題:5個縱向視圖(每個都是一個NavigationController的「根視圖」並且連接到TabBar)...除了應該改變旋轉角度的那個外,你可以保留所有這些視圖。我實現了一個Cover-Flow-View,在更改設備旋轉時顯示,它工作得很好。 – samsam 2010-05-06 09:46:34

相關問題