gpt4 book ai didi

iPad 方向/框架尺寸问题

转载 作者:行者123 更新时间:2023-12-01 07:32:05 31 4
gpt4 key购买 nike

在“View Did Load”中,我试图确定 View 的大小,以便我可以适本地调整 subview 的大小。我希望它始终围绕屏幕的长度和宽度拉伸(stretch),而不管方向如何。

quest *anview = [[quest alloc] initWithFrame: CGRectMake(50, 50, self.view.frame.size.width-100, self.view.frame.size.height-100)];
self.aquest=anview;

但这总是返回 748 的宽度和 1024 的高度,而当我处于横向时它应该返回相反的值。我知道您无法在模拟器上获得方向,但在设备上也会出现这种情况。当我得到方向时:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSLog(@"device orientation:%d",orientation);

我正确地获得了方向,但无论方向如何,此日志语句都会返回 748/1024。

    NSLog(@"size w:%f",self.view.frame.size.width);
NSLog(@"size h:%f",self.view.frame.size.height);

有人知道这是怎么回事吗?这和我把它放在 viewdidLoad 方法中有关系吗?我应该把它放在 viewWillAppear 还是 viewDidAppear 中?

最佳答案

尝试使用 bounds 属性而不是 frame

View 始终以纵向模式创建然后旋转,即使您以横向启动应用程序也是如此。您应该能够通过将 subview 的大小设置为相对于父级的纵向大小并将自动缩放掩码设置为 UIViewAutoresizingMaskFlexibleWidth|UIViewAutoresizingFlexibleHeight 来保持 subview 拉伸(stretch),提供 shouldAutorotateToInterfaceOrientation: 返回 YES正确的设备方向。它还将保持与顶部和左边距的距离,除非您向掩码添加不同的 UIViewAutoresizingFlexibleMargin

关于iPad 方向/框架尺寸问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3794447/

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