gpt4 book ai didi

ios - 将 autoResizingMask 与 CGRectZero 一起使用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:33 26 4
gpt4 key购买 nike

我正在为表格 View 的部分构建页脚。页脚的高度将在 heightForFooterInSection 中指定,因此在 viewForFooterInSection 中,我只想添加 subview 并指定页脚 View 应填充指定的任何页脚高度(此页脚大小将是动态的)。因此,我使用 CGRectZero 作为初始框架并告诉页脚 View 展开以填充其父 View 。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *footerView = [[UIView alloc] initWithFrame:CGRectZero];
footerView = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
footerView = [UIColor greenColor];
return footerView;
}

这按预期工作 - 表格 View 的页脚完全被绿色 View 填充。

但现在我想在页脚中添加一个 UITextView。 TextView 应填充相同的空间,但保留 5 点边框:

{
UIView *footerView = [[UIView alloc] initWithFrame:CGRectZero];
footerView = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
footerView = [UIColor greenColor];

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(footerView.frame, 5, 5)];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textView.backgroundColor = [UIColor redColor];

[footerView addSubview:textView];
return footerView;
}

TextView 根本不显示,而不是填充页脚 View (具有 5 点边距)。它可能有一个 CGRectZero 的框架(或者甚至可能是 -5 x -5?)。但是,如果我将 inset 设置为 0, 0,它会按预期扩展。

请问这是怎么解释的?如果我不能为初始框架使用 CGRectZero 的插图,那么当无法知道 footerView 的框架时,我应该使用什么?

最佳答案

CGRectInset 将基于现有矩形创建一个矩形。它不再引用页脚 View :仅当它计算一次时。在这种情况下,由于您试图插入一个大小为零的矩形,因此这适用于文档:

Discussion. The rectangle is standardized and then the inset parameters are applied. If the resulting rectangle would have a negative height or width, a null rectangle is returned.

因此,您正在创建带有空矩形的标签。

我会创建一个“典型”尺寸的页脚,然后是一个带有您想要的 autoResizingMask 的适当大小的标签,然后然后将您的 footerView 设置为零(如果您希望将其设置为零) .

关于ios - 将 autoResizingMask 与 CGRectZero 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13905144/

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