iOS 6:旋转后忽略父模式的modalPresentationStyle [英] iOS 6: Parent modal's modalPresentationStyle ignored after rotation
问题描述
使用带有iOS6的iPad,我们有一个错误,即模态视图控制器将扩展到全屏,即使它被告知
使用表单演示样式。但是,只有当有两个模态,父模式及其子模式时才会发生这种情况。
With iPad with iOS6, we have this bug where a modal view controller will expand to full screen, even if it is told to be using "form sheet" presentation style. But, this happens only if there are two modals, a parent one and its child.
所以这就是第一个模态的创建和呈现方式:
So this is how the first modal is created and presented:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is my application's root controller
这是子模态的创建方式赠送:
This is how the child modal is created and presented:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is the navigationController from above
所以当从横向旋转到肖像时,即使我们旋转回横向,父模态也会扩展到全屏并保持这种状态。
So when rotating from landscape to portrait, the parent modal will expand to full screen and remain that way even if we rotate back to landscape.
当我们有父模态本身(没有子模态)时,那么它按预期工作,它保持表单样式。
When we have the parent modal all by itself (no child modal), then it works as expected, which is that it remains in form sheet style.
请注意,这只发生在iOS6(设备和模拟器)上,并且不会发生在iOS 5上(模拟器并报告由测试人员工作)。
Note that this happens on iOS6 only (device and simulator) and doesn't happen on iOS 5 (simulator and reported to work by testers).
到目前为止,我已尝试以下方法但未成功:
So far, I have tried the following without success:
- 设置
wantsFullScreenLayout
到否
- 强制
wantsFullScreenLayout
通过覆盖它总是返回NO
- 确定我的控制器在里面导航控制器还指定
UIModalPresentationFormSheet
- 实现
preferredInterface OrientationForPresentation
- 升级到iOS 6.0.1
- setting
wantsFullScreenLayout
toNO
- forcing
wantsFullScreenLayout
to always returnNO
by overriding it - Making certain my controllers inside the navigation controller also specify
UIModalPresentationFormSheet
- implementing
preferredInterfaceOrientationForPresentation
- upgrade to iOS 6.0.1
谢谢!
更新:
因此,我调整了Apple Developer Forums的响应( https://devforums.apple.com/message/748486#748486 )以便它适用于多个嵌套模态。
UPDATE: So, I adapted the response from the Apple Developer Forums (https://devforums.apple.com/message/748486#748486) so that it works with multiple nested modal.
- (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];
}
推荐答案
不确定这是否应该是被认为是一个bug,我很好奇iOS 7将带来什么,但目前这个问题的解决方法是将modalPresentationStyle设置为child-viewController的UIModalPresentationCurrentContext。
Not sure if this should be considered as a bug and I'm curious what iOS 7 will bring, but the current workaround for this issue is to set modalPresentationStyle to UIModalPresentationCurrentContext for the child-viewController.
Set modalPresentationStyle = UIModalPresentationCurrentContext
这使得孩子仍然可以作为FormSheet呈现,但是会阻止父母在轮换时调整大小到全屏。
This makes the child still beeing presented as FormSheet but prevents the parent from beeing resized to fullscreen on rotation.
Dirk
这篇关于iOS 6:旋转后忽略父模式的modalPresentationStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!