只需將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,這當然也迫使肖像模式控制器進入橫向模式。另一方面,我可以將肖像模式控制器設置爲正確的方向,但這也會將橫向模式控制器旋轉爲肖像模式。我似乎無法讓這兩個工作。
任何想法?
分類是**添加新方法**,而不是**覆蓋**現有的。 –
當頂視圖控制器沒有實現新的方向方法時,這會失敗。如果頂級VC是Apple內置的一些VC(特別是ABPersonViewController的choose-photo VC)。爲了解決這個問題,請檢查從頂端VC返回的值:'UIInterfaceOrientationMask topMask = [self.topViewController supportedInterfaceOrientations];返回topMask? topMask:UIInterfaceOrientationMaskAllButUpsideDown;' – Yonat