gpt4 book ai didi

iOS 6 : Parent modal's modalPresentationStyle ignored after rotation

转载 作者:IT王子 更新时间:2023-10-29 07:46:05 25 4
gpt4 key购买 nike

对于 iOS6 的 iPad,我们有一个错误,模态视图 Controller 将扩展到全屏,即使它被告知使用“表单”演示文稿样式。但是,只有当有两个模态,一个父模态和它的子模态时,才会发生这种情况。

这就是第一个模态框的创建和呈现方式:

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
  • 确保我的导航 Controller 内的 Controller 也指定 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 设置为 child-viewController 的 UIModalPresentationCurrentContext。

Set modalPresentationStyle = UIModalPresentationCurrentContext

这使得子项仍然显示为 FormSheet,但阻止父项在旋转时调整为全屏。

德克

关于iOS 6 : Parent modal's modalPresentationStyle ignored after rotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13347906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com