iPad:UIModalPresentationFormSheet在横向模式下失败

时间:2011-09-22 15:24:34

标签: objective-c ipad modalviewcontroller uimodalpresentationstyle

我们的iPad版本存在下一个问题。

我在UITabBar中有一个NavigationController。我希望显示一个外观和感觉类似于电子邮件表单的表单。

我使用相同的代码来显示模型居中:

// View to be displayed in the modal
AdhocViewController *controller = [[AdhocViewController alloc] initWithNibName:@"AdhocViewController" bundle:[NSBundle mainBundle]];
controller.caller = self;

// The form will need a navigation bar to cancel or save the form
UINavigationController *modalViewNavController = [[UINavigationController alloc] 
                                               initWithRootViewController:controller];

// Configurate the modal presentation and transition
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet;

// Show the new view
[self presentModalViewController:modalViewNavController animated:YES];

此代码在纵向模式下完美运行,但在横向上,视图部分显示在屏幕外...我还没有找到解决问题的方法。

我测试了我在这里找到的一些解决方案......

尝试在预设模型视图后添加下一行以调整其大小,但不能正常工作

controller.view.superview.frame = CGRectMake(0, 0, 600, 700);
controller.view.superview.center = self.view.center;

有任何建议吗?

谢谢,

伊万

StackOverflow中的引用:

3 个答案:

答案 0 :(得分:5)

使用iOS7,技巧是将modalTransitionStyle设置为UIModalTransitionCrossDissolve。

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:navigationController animated:YES completion:nil];
navigationController.view.superview.frame = CGRectMake(0, 0, 800, 544);
navigationController.view.superview.center = self.view.center;

https://coderwall.com/p/vebqaq

答案 1 :(得分:1)

最后代码是下一个:

// Remove the modalTransitionStyle to enable the default behaviour and change to PageSheet
modalViewNavController.modalPresentationStyle = UIModalPresentationPageSheet;
// Present the modal view and adapt the center depending of the orientation
[self presentModalViewController:modalViewNavController animated:YES];

UIDeviceOrientation _orientation = [controller interfaceOrientation];
if (UIDeviceOrientationIsPortrait(_orientation)){
    modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10);
} else {
    modalViewNavController.view.superview.center = CGPointMake(768/2 - 10, 1024/2);
}

+10和-10是因为聋人的模态的NavigationController在屏幕之外。

这是......一个糟糕的解决方案:SS但是有效......虽然如果有人有建议会很高兴知道。

如果我需要为两个方向包含相同的中心,那么可能是超视图的方向不是预期的方向。

在此解决方案中,当我在纵向方向上关闭模态视图时,至少在iPad模拟器上,它会自动旋转到纵向模式...

最终解决方案是在主控制器UITabBar上执行presentModalViewController,并更新要在其上执行的dismiss方法。

[tabbar presentModalViewController:modalViewNavController animated:YES];

UIDeviceOrientation _orientation = [controller interfaceOrientation];
if (UIDeviceOrientationIsPortrait(_orientation)){
    modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10);
} else {
    modalViewNavController.view.superview.center = CGPointMake(1024/2, 768/2 + 10);
}

最后!!!!

谢谢,

伊万

答案 2 :(得分:0)

在iOS 7中,为了解决键盘显示后模态视图控制器出现在左侧的问题(当我在UIModalPresentationFormSheet中呈现EKEventEditViewController时遇到的问题,我这样做:

[self presentViewController:modalViewController animated:YES completion:^{
    modalViewController.view.superview.center = self.view.center;
}];