即使改变框架,UIView高度也不会降低

时间:2016-05-18 10:53:20

标签: ios objective-c uitableview uiview collapse

我的UITableView中有两种类型的单元格 - commonCell和expandedCell。膨胀的单元在水龙头上展开,显示完整的描述,并且标签相应地调整自身,即标签高度是动态的。 UITableView snapshot showing cell with attachment opened

以下所有代码都写在 - tableView:heightForRowAtIndexPath:对于展开的单元格:

     // Debug area log before changing frame

     //Printing description of viewAttachment: 
     //UIView: 0x7f8f84d8b050; frame = (16 107; 288 20); autoresize = RM+BM; tag = 314; layer = CALayer: 0x7f8f84d7a340

    CGFloat height =[[HSHelper sharedInstance]  getLabelSizeFortext:help.helpDescription forWidth:labelDescText.frame.size.width                                                                        WithFont:kFontRobotoRegular(15).height;
    height = (height<20.0)? 20.0 + 20: height + 10;

    CGFloat heightAttachment = 0.0;
    if (help.helpAttachmentName.length != 0) {
        heightAttachment = [HSHelper sharedInstance].isiPad ? 35.0 :20.0;
    } else {
        CGRect framee = viewAttachment.frame;
        framee.size.height = 0.0f;
        viewAttachment.frame = framee;
    }

    // Debug area log after changing frame

    //Printing description of viewAttachment: 
    //UIView: 0x7f8f84d8b050; frame = (16 107; 288 0); autoresize = RM+BM; tag = 314; layer = CALayer: 0x7f8f84d7a340

    return height + 23.0 + heightAttachment + 34.0;

图像显示问题: UITableView snapshot showing cell without attachment opened

正如您在我的代码中看到的那样,注释部分显示了我的调试区域中打印的结果,该结果清楚地显示了viewAttachment的高度已被更改。但是,模拟器快照图像仍然显示没有附加文件的空白区域应该折叠。

我还在故事板中将viewAttachment的高度设置为'&lt; ='而不是'='。

请帮我解决这个奇怪的问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试设置

view.translatesAutoresizingMaskIntoConstraints=YES;