Gen*_*sST 33 modal-dialog rotation ipad ios
使用iOS6的iPad,我们有这个错误,即模态视图控制器将扩展到全屏,即使它被告知使用"表单"演示样式.但是,只有当有两个模态,一个父模型及其子模式时,才会发生这种情况.
这就是第一个模态的创建和呈现方式:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is my application's root controller
Run Code Online (Sandbox Code Playgroud)
这是创建和呈现子模态的方式:
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[parentController presentModalViewController:navigationController animated:YES];
// parentController is the navigationController from above
Run Code Online (Sandbox Code Playgroud)
因此,当从横向旋转到纵向时,即使我们旋转回横向,父模式也会扩展到全屏并保持这种状态.
当我们拥有父模态本身(没有子模态)时,它按预期工作,即它保持在表单样式中.
请注意,这只发生在iOS6(设备和模拟器)上,并且不会发生在iOS 5(模拟器上,并报告由测试人员工作).
到目前为止,我已经尝试了以下但没有成功:
wantsFullScreenLayout为NOwantsFullScreenLayout总是NO通过覆盖它来返回UIModalPresentationFormSheetpreferredInterfaceOrientationForPresentation谢谢!
更新:所以,我调整了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];
}
Run Code Online (Sandbox Code Playgroud)
不确定这是否应该被视为一个错误,我很好奇iOS 7将带来什么,但目前这个问题的解决方法是将modalPresentationStyle设置为子视图控制器的UIModalPresentationCurrentContext.
Set modalPresentationStyle = UIModalPresentationCurrentContext
Run Code Online (Sandbox Code Playgroud)
这使得孩子仍然可以作为FormSheet呈现,但是防止父母在轮换时调整大小到全屏.
短剑
我在这里看到两个问题。
1)在iOS 6中,该方法presentModalViewController:animated:已被弃用,请尝试使用presentViewController:animated:completion:
(尽管这可能没有帮助,但您仍然可能想要这样做)
2) 在 iOS 6 中,容器控制器(例如UINavigationController)以某种方式出现,不会向其子级重新发送自动旋转消息。尝试子类化UINavigationController并重新定义相应的自动旋转方法以发送给所有子级。这可能会有所帮助。
| 归档时间: |
|
| 查看次数: |
5627 次 |
| 最近记录: |