2012-10-09 45 views
4

只需將iOS 5應用程序更新到iOS 6,當然也偶然遇到了界面方向問題。我現在已經知道事情發生了變化,我甚至知道發生了什麼變化,但我似乎無法自己管理它。iOS6界面方向破損

我的應用程序由幾個視圖控制器組成,它們被推送到導航控制器上。所有的viewcontrollers應該是橫向的,除了一個,應該是縱向的。在iOS 5中一切正常,但現在縱向模式下的一個控制器也顯示爲橫向模式,當然會變形。

我的iOS 5代碼看上去像是:

的ViewController在橫向模式下:

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

的ViewController在人像模式:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown); 
} 

現在,我發現了在iOS中的變化6我實施了

AppDelegate :(允許所有的方向,像在plist中)

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ 
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

的ViewController在橫向模式下:(限制方向爲橫向模式)

- (NSUInteger) supportedInterfaceOrientations{ 
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight 
} 

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 

- (BOOL)shouldAutorotate{ 
return YES; 
} 

的ViewController在人像模式:(限制方向到肖像模式)

- (NSUInteger) supportedInterfaceOrientations { 
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown; 
} 

- (BOOL)shouldAutorotate { 
return YES; 
} 

從我的理解應該起作用,但事實是它比以前更少。 首先,橫向模式viewcontrollers不停留在橫向模式,他們在各個方向自由旋轉,這當然不是我想要的。其次,在人像模式中的視圖 - 控制將

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!' 

一些試驗和錯誤我似乎只能夠鎖定所有控制器爲橫向模式後崩潰,通過plist文件/的appdelegate,這當然也迫使肖像模式控制器進入橫向模式。另一方面,我可以將肖像模式控制器設置爲正確的方向,但這也會將橫向模式控制器旋轉爲肖像模式。我似乎無法讓這兩個工作。

任何想法?

回答

7

好,我固定它。

我做了一個類別的UINavigationController

@implementation UINavigationController (Rotation_IOS6) 

-(BOOL)shouldAutorotate 
{ 
return [self.topViewController shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
return [self.topViewController supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
return [self.topViewController preferredInterfaceOrientationForPresentation]; 
} 

@end 

到視圖控制器的值轉發到navigationcontroller ...

我還與presentViewController更換presentModalViewController作爲第一個現在已經過時。

順便說一句,是的,作爲我的appdelegate中的錯字...這是正確的。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; 
} 
+2

分類是**添加新方法**,而不是**覆蓋**現有的。 –

+1

當頂視圖控制器沒有實現新的方向方法時,這會失敗。如果頂級VC是Apple內置的一些VC(特別是ABPersonViewController的choose-photo VC)。爲了解決這個問題,請檢查從頂端VC返回的值:'UIInterfaceOrientationMask topMask = [self.topViewController supportedInterfaceOrientations];返回topMask? topMask:UIInterfaceOrientationMaskAllButUpsideDown;' – Yonat

0

就觀察到,在你的UIInterfaceOrientationMaskLandscapeLeft中的appdelegate LandscapeRight失蹤 如果它只是錯字寫入兩次,改正後仍存在這個問題

我發現只有rootViewControllers - (BOOL)shouldAutorotate;打電話。這裏ur rootViewController是NavigationController。而對於推送viewController這不會被調用,所以你必須決定方向支持從navControllers方法只推動視圖。 繼爲我工作我navControllers推的viewController
覆蓋UINavigationControllers方法

- (BOOL)shouldAutorotate; 
- (NSUInteger) supportedInterfaceOrientations; 

代碼會是這樣的。在V

@implementaion UINavigationController(Rotation) 

- (BOOL)shouldAutorotate 
{ 
return YES; 
} 

- (NSUInteger) supportedInterfaceOrientations 
{ 
    NSArray *viewsArray = [self viewController]//stack of pushed controller 

    NSUInteger orientationToReturn = assignAllMask; 

    for(UIViewController *temp in viewsArray) 
    { 
     if([temp isKindOfClass:MyOnlyLandscapeViewController] == YES) 
     { 
      orientationToReturn = assignLandscapeMask; 
      break; 
     } 
     else if([temp isKindOfClass:MyOnlyPortraitViewController] == YES) 
     { 
      orientationToReturn = assignPortraitMask; 
      break; 
     } 
    } 

    return orientationToReturn; 
} 

@end 
+0

Thx的努力,但我已經修復它(經過一些更多的試驗和錯誤)。我認爲這也與已棄用的模態視圖控制器功能有關。看到我的答案。 –