gpt4 book ai didi

ios - 如何理解 table.autoresizingMask 的行为?

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

我了解到在单 View 应用程序中设置覆盖整个主视图(全宽和全高)的 UITableView 的正确方法是,在 viewDidLoad:

table = [[UITableView alloc] initWithFrame:self.view.bounds];
table.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
[self.view addSubview:table];

请注意,如果物理 iPad 2 处于横向模式,并且上面的 self.view.bounds 打印在 viewDidLoad 中,它将显示:{{0, 0}, {768, 1004}}。所以我的想法是:不要担心宽度和高度不正确,因为 UIViewAutoresizingFlexibleWidthUIViewAutoresizingFlexibleHeight 会自动设置正确的宽度和大小。

所以我实际上尝试将上面的第一行替换为:

table = [[UITableView alloc] init];

table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

甚至

table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1004, 768)];

或最终的“正确值”:

table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1024, 748)];

当 iPad 2 处于横向位置时。但是现在表格不会完全扩展到整个主视图。那么这里的管理原则是什么?宽高可以设置错,但一定是错在{768, 1004}?它不能与其他值“不正确”吗?如果没有给出 CGRect,或者给出了一些伪值 {200, 200}viewDidLoad 中的代码应该做什么来制作表格是否具有完整的主视图的宽度和高度,无论是横向模式还是纵向模式?

最佳答案

不要使用bounds,而是使用frame:

table = [[UITableView alloc] initWithFrame:self.view.frame];
table.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;

关于ios - 如何理解 table.autoresizingMask 的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12207633/

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