iPad:UIModalPresentationFormSheet 在横向模式下失败

发布于 2024-12-06 00:52:00 字数 1971 浏览 0 评论 0原文

我们的 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;

有什么建议吗?

谢谢,

Ivan

参考文献StackOverflow:

We've the next problem in our iPad version.

I've a NavigationController inside a UITabBar. I want to show a Form with a look&feel similar than the e-Mail form.

I use the same code to show a model centered:

// 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];

This code works perfectly on portrait mode, but on landscape the view appears partially out of the screen ... and I didn't found yet the way to solve it.

I test some of the solutions I found here ...

And try to add the next lines after preset the model view to resize it, but doesn't work it out

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

Any suggestion?

Thanks,

Ivan

References in StackOverflow:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨落□心尘 2024-12-13 00:52:00

对于 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

With iOS7 the trick is to set the modalTransitionStyle to 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

会傲 2024-12-13 00:52:00

最后是下一个代码:

// 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,并更新关闭方法也可以在其上执行。

[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);
}

最后!!!!

谢谢你,

伊万

Finally the code was the next:

// 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);
}

The +10 and -10 is because by deafult the NavigationController of the modal was out of the screen on top.

It is ... a crappy solution :SS but works ... Although if anybody have suggestions would be nice to know.

Seams that if I need to include the same center for both orientation, maybe the orientation of the superview is not the expected one.

In this solution, when I dissmiss the modal view on Portrait orientation, at least on the iPad simulator, it rotate to portrait mode automatically ...

The final solution was to execute the presentModalViewController over the main controller, the UITabBar, and update the dismiss method to be executed also over it.

[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);
}

Finally!!!!

Thank you,

Iván

潜移默化 2024-12-13 00:52:00

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

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

In iOS 7, to solve the problem of the modal view controller to appear to the left after apparition of the keyboard (problem that I have when I present an EKEventEditViewController in UIModalPresentationFormSheet, I do :

[self presentViewController:modalViewController animated:YES completion:^{
    modalViewController.view.superview.center = self.view.center;
}];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文