添加:您可以在github ios6rotations上訪問此項目抱歉,有人問有關iOS 6屏幕旋轉的問題,但這確實讓我很痛苦。而且我仍然無法完全理解它-由于某些原因,它在某些情況下的行為有所不同。我的測試應用程序中具有以下簡單的視圖層次結構: 我要實現的目標是- 將藍色控制器僅橫向放置,將紅色控制器僅縱向放置。我有一個UINavigationController的子類,里面有這樣的代碼:@implementation CustomNavController- (BOOL)shouldAutorotate{
return [[self.viewControllers lastObject] shouldAutorotate];}- (NSUInteger)supportedInterfaceOrientations{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];}@end在我的藍色控制器中,我實現了這一點:- (BOOL)shouldAutorotate {
return YES;}- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;}在紅色控制器中:- (BOOL)shouldAutorotate {
return YES;}- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;}現在,我有以下行為:應用在橫向模式下啟動(確定)當我按下按鈕時,我的紅色控制器也按橫向顯示(這不行,因為必須在“人像”中顯示)它成功旋轉為縱向但不向后旋轉為橫向如果我將紅色控制器留在人像模式下,則我的藍色控制器(僅限橫向)會以人像模式顯示。PS我所有的旋轉方法(上面發布的)都被正常調用(順便說一下,為什么這些方法在每次屏幕轉換時都會被調用多次-5-6次)- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 不被推叫所有(除portraitUpsideDown外)方向都包含在plist中。問題是-如何在每個控制器中強制旋轉到支持的方向?我建議您在此處發布(作為答案)任何100%正常工作的代碼來處理ios6中的旋轉(例如,如果您的iPad使用SplitController的話)-我會將這個問題保留在收藏夾中,以在需要時將它們全部放在一個位置處理一些特定情況。干杯!添加:請不要將此作為從風景到肖像的答案發布,我希望有一種更優雅的方法。
3 回答
慕村225694
TA貢獻1880條經驗 獲得超4個贊
我的兩分錢價值。
您可以快速顯示一個空的透明模式視圖,然后將其關閉,這可以作為快速解決方法,方法是在ViewController和ViewControllerSecond類的ViewDidLoad:或viewWillAppear:上。
此外,在情節提要中,您可以將ViewController類的方向設置為在視覺上呈現風景。
MYYA
TA貢獻1868條經驗 獲得超4個贊
使用此行以編程方式更改方向... 工作100%
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
并且在那時添加此行時,會出現一個警告,要刪除此警告,只需在實現文件的頂部添加以下代碼。
@interface UIDevice (MyPrivateNameThatAppleWouldNeverUseGoesHere)- (void) setOrientation:(UIInterfaceOrientation)orientation;@end
然后在波紋管方法中,如果需要,只需編寫此代碼。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
// Return your supported orientations
if (currentMainView==blueOne) {
return toInterfaceOrientation== UIInterfaceOrientationPortrait;
}}- 3 回答
- 0 關注
- 589 瀏覽
添加回答
舉報
0/150
提交
取消
