iOS 6: Parent modal#39;s modalPresentationStyle ignored after rotation(iOS 6:旋转后忽略父模式的 modalPresentationStyle)
问题描述
对于 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设置为NO - 强制
wantsFullScreenLayout总是通过覆盖返回NO - 让导航控制器中的某些控制器也指定
UIModalPresentationFormSheet - 实现
preferredInterfaceOrientationForPresentation - 升级到 iOS 6.0.1
- setting
wantsFullScreenLayouttoNO - forcing
wantsFullScreenLayoutto always returnNOby overriding it - Making certain my controllers inside the navigation controller also specify
UIModalPresentationFormSheet - implementing
preferredInterfaceOrientationForPresentation - upgrade to iOS 6.0.1
谢谢!
更新:因此,我调整了 Apple 开发者论坛 (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];
}
推荐答案
不确定这是否应该被视为一个错误,我很好奇 iOS 7 会带来什么,但目前解决这个问题的方法是将 modalPresentationStyle 设置为子视图控制器的 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.
德克
这篇关于iOS 6:旋转后忽略父模式的 modalPresentationStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 6:旋转后忽略父模式的 modalPresentationStyle
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
