模型视图的 iPad 方向问题

发布于 2024-12-18 02:48:49 字数 619 浏览 2 评论 0原文

我在主视图中有按钮,当我单击主视图按钮时,模型视图 Mv1 打开。Mv1 模型视图宽度和高度为 730 和 620。在纵向模式下,Mv1 模型视图在主视图中显示中心,但在横向模式下,Mv1 模型视图显示水平居中,但在主视图中不显示垂直居中。

主视图按钮单击编码:-

Mv1 *Mv1obj = [[Mv1 alloc]initWithNibName:@"Mv1" bundle:nil];
UINavigationController*nav[[UINavigationControlleralloc]initWithRootViewController:Mv1obj];
nav.modalPresentationStyle=UIModalPresentationFormSheet;
nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nav animated:YES];
nav.view.superview.frame = CGRectMake(0, 0,730,620);
nav.view.superview.center = self.view.center;

如果知道请重播,提前致谢。

I have button in main view,when i click on main view button model view Mv1 is open.Mv1 model view width and height is 730 and 620.in portrait mode Mv1 model view show center in main view but in landscape mode Mv1 model view show center horizontally but does not show center vertically in main view.

main view button click coding:-

Mv1 *Mv1obj = [[Mv1 alloc]initWithNibName:@"Mv1" bundle:nil];
UINavigationController*nav[[UINavigationControlleralloc]initWithRootViewController:Mv1obj];
nav.modalPresentationStyle=UIModalPresentationFormSheet;
nav.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:nav animated:YES];
nav.view.superview.frame = CGRectMake(0, 0,730,620);
nav.view.superview.center = self.view.center;

if know please replay,thanks in advance.

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

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

发布评论

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

评论(1

亣腦蒛氧 2024-12-25 02:48:49

这里的问题是,您在设置中心时需要考虑方向,因此将行:

nav.view.superview.center = self.view.center;

替换为类似这样的内容

UIDeviceOrientation orientation = ([[UIDevice currentDevice] orientation]);
const CGPoint centerPortait = self.view.center;
const CGPoint centerLandscape = CGPointMake(centerPortait.y, centerPortait.x);
const CGPoint center = (orientation == UIDeviceOrientationPortrait) ? centerPortait : centerLandscape;
nav.view.superview.center = center;

将正确居中模态视图。

The issue here is that you need to account for orientation when setting the center, so replace the line:

nav.view.superview.center = self.view.center;

with something like

UIDeviceOrientation orientation = ([[UIDevice currentDevice] orientation]);
const CGPoint centerPortait = self.view.center;
const CGPoint centerLandscape = CGPointMake(centerPortait.y, centerPortait.x);
const CGPoint center = (orientation == UIDeviceOrientationPortrait) ? centerPortait : centerLandscape;
nav.view.superview.center = center;

this will correctly center the modal view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文