对于带有 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];
}