gpt4 book ai didi

ios - 不正确的 View 大小 ios

转载 作者:行者123 更新时间:2023-11-29 11:06:57 25 4
gpt4 key购买 nike

我正在使用 UIViewController 来显示我的 View 。我的 View 已在界面生成器中创建。

现在这些是 View 的下一个参数:

宽度:568高度:320方向:横向

在 ViewController 中我有下一个代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

在 info.plist 中,我只添加了左右两个界面方向。

但是当我尝试在代码中输出我的 View 宽度时,我得到 320,当我尝试输出高度时,它在控制台 568 中记下,但我期望 320 而不是。

我不知道为什么会这样。有什么建议吗?

即使我添加这个:

[self.view setFrame:CGRectMake(0, 0, 568, 320)]; 在 vi​​ewDidLoad 方法中。即使那样我的高度也不正确

我需要知道我在这个方法中使用的宽度尺寸:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
CGFloat width = 0.0f;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
width = 568.0f;
} else {
width = 1024.0f;
}
NSInteger page = scrollView.contentOffset.x / width;
NSLog(@"%d", page);
}

现在我使用宽度的硬编码变量,但怎么会这样。为什么我不能使用 self.view.frame.size.width 因为两边互相交换 - 因为。

最佳答案

也许您在出现方向之前在 viewDidLoad 方法中打印宽度和高度。尝试在 viewWillAppear 上或使用 performSelector:afterDelay:

打印它

可能影响 View 尺寸的另一件事是如何在界面构建器上设置自动调整大小掩码(右侧面板上 x、y、高度、宽度部分下方的红色箭头)

关于ios - 不正确的 View 大小 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13184671/

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