permission - iOS 6:旋轉後忽略父模式的modalPresentationStyle
ipad layout (2)
使用帶有iOS6的iPad,我們有一個錯誤,即模態視圖控制器將擴展到全屏,即使它被告知使用“表單”演示樣式。 但是,只有當有兩個模態,即父模式及其子模式時,才會發生這種情況。
這就是第一個模態的創建和呈現方式:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is my application's root controller
這是創建和呈現子模態的方式:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is the navigationController from above
因此,當從橫向旋轉到縱向時,即使我們旋轉回橫向,父模式也會擴展到全屏並保持這種狀態。
當我們擁有父模態本身(沒有子模態)時,它按預期工作,即它保持在表單樣式中。
請注意,這僅發生在iOS6(設備和模擬器)上,並且不會發生在iOS 5上(模擬器並報告由測試人員工作)。
到目前為止,我已經嘗試了以下但沒有成功:
- 將
wantsFullScreenLayout
設置為NO
- 強制
wantsFullScreenLayout
總是通過覆蓋它返回NO
- 在導航控制器中確定我的控制器也指定
UIModalPresentationFormSheet
- 實現
preferredInterfaceOrientationForPresentation
- 升級到iOS 6.0.1
謝謝!
更新 :所以,我調整了Apple開發者論壇( https://devforums.apple.com/message/748486#748486 )的響應,以便它可以與多個嵌套模式一起使用。
- (BOOL) needNestedModalHack {
return [UIDevice currentDevice].systemVersion.floatValue >= 6;
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
// We are the top modal, make to sure that parent modals use our size
if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
for (UIViewController* parent = self.presentingViewController;
parent.presentingViewController;
parent = parent.presentingViewController) {
parent.view.superview.frame = parent.presentedViewController.view.superview.frame;
}
}
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
// We are the top modal, make to sure that parent modals are hidden during transition
if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
for (UIViewController* parent = self.presentingViewController;
parent.presentingViewController;
parent = parent.presentingViewController) {
parent.view.superview.hidden = YES;
}
}
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// We are the top modal, make to sure that parent modals are shown after animation
if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) {
for (UIViewController* parent = self.presentingViewController;
parent.presentingViewController;
parent = parent.presentingViewController) {
parent.view.superview.hidden = NO;
}
}
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
}
不確定這是否應該被視為一個錯誤,我很好奇iOS 7將帶來什麼,但目前這個問題的解決方法是將modalPresentationStyle設置為子視圖控制器的UIModalPresentationCurrentContext。
Set modalPresentationStyle = UIModalPresentationCurrentContext
這使得孩子仍然可以作為FormSheet呈現,但是防止父母在輪換時調整大小到全屏。
短劍
您需要在主視圖後實例化導航控制器。 這樣您就可以在每個視圖中管理旋轉。
如果您的AppDelegate RootViewController是導航控制器,您將無法使用本機功能管理旋轉。