Ios 使用带有CGRectZero的autoResizingMask

Ios 使用带有CGRectZero的autoResizingMask,ios,cocoa-touch,uitableview,uiview,autoresizingmask,Ios,Cocoa Touch,Uitableview,Uiview,Autoresizingmask,我正在为tableview的部分构建页脚。页脚高度将在heightforfooterInstitution中指定,因此在viewforfooterInstitution中,我只想添加子视图,并指定页脚视图应填充指定的任何页脚高度(此页脚大小将是动态的)。因此,我使用CGRectZero作为初始帧,并告诉页脚视图展开以填充其父视图 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)sec

我正在为tableview的部分构建页脚。页脚高度将在
heightforfooterInstitution
中指定,因此在
viewforfooterInstitution
中,我只想添加子视图,并指定页脚视图应填充指定的任何页脚高度(此页脚大小将是动态的)。因此,我使用
CGRectZero
作为初始帧,并告诉页脚视图展开以填充其父视图

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectZero];
    footerView = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    footerView = [UIColor greenColor];
    return footerView;
}
这与预期的一样-表视图的页脚完全被绿色视图填充

但是现在我想在页脚中添加一个
UITextView
。文本视图应填充相同的空间,但保留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;
}
文本视图根本不显示,而不是填充页脚视图(带有5点边距)。它可能有一个
CGRectZero
(甚至可能是-5x-5?)的帧。但是,如果我将inset设置为0,0,它将按预期进行扩展


对此有何解释?如果我不能使用插入的
CGRectZero
作为初始帧,那么当无法知道footerView的帧时,我应该使用什么呢?

我猜TextView会在后台创建内容,因此在初始化时它是空的。我通常会使用
[string sizeWithFont:constrainedToSize:lineBreakMode:]

CGSize size = [aString sizeWithFont:[UIFont systemFontOfSize:12.0] constrainedToSize:CGSizeMake(320,500) lineBreakMode:NSLineBreakByWordWrapping];
CGRect frame = CGRectMake(0, 0, size.width, size.height);

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

讨论。 对矩形进行标准化,然后选择插入参数 应用如果生成的矩形具有负高度或 宽度,则返回空矩形

因此,您正在使用空矩形创建标签


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

您的最后一句话是正确的答案,只是不需要将帧设置为零。页脚的大小由表视图调整为适当的大小,因此如果您需要页边距、布局等,可以任意调整页脚大小。@jrturton:是的,但出于某种原因,他似乎希望页脚的大小为零,这样做没有什么害处。谢谢。是的,没有要求将它设置回零,我只是在没有其他任何东西的情况下使用它。