【发布时间】:2012-11-12 16:55:12
【问题描述】:
对于 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];
}
【问题讨论】:
-
有人给我指出了苹果开发者论坛,我发现了这个:devforums.apple.com/message/748486
-
呈现多种模式显然打破了 Apple 所说的你应该做事的方式。如果您最终做这样的事情违背了 Apple 的建议,那么预计会出现这样的问题。还要考虑你可能有一个非常糟糕的设计。如果你想像这样显示多个 viewController,你应该在单个模态演示中使用包含或 navigationController。如果在 iOS 6.3 中再次出现问题,你会怎么做?
-
@Ade:本文档提到可以链接模态视图控制器:developer.apple.com/library/ios/#featuredarticles/…
-
感谢您指出这一点,因为我认为您试图从单个 viewController 父级(非链接)呈现多个模态 viewController 是值得的。我个人一直在导航控制器中拥有 viewControllers。感觉自己像个混蛋;)
标签: ios ipad rotation modal-dialog