我有一个 tableViewHeader UIView,其中包含一些动态元素(确切地说是大小不同的 UILabel)。我在 IB 中设置了 UIView,将所有内容都连接起来,并尝试在 sizeToFit 之后根据我的标签大小更改框架原点。
如果我在 setFrame 调用后记录新帧,它实际上会显示更新的来源,但它们不会显示在模拟器上。标签会改变高度,但原点不会改变。
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame;
CGFloat baseOffset = titleLbl.frame.origin.y;
offset = titleLbl.frame.size.height;
self.titleLbl.text = destObject.title;
self.titleLbl.font = [UIFont fontWithName:@"Avenir-Heavy" size:22];
[self.titleLbl sizeToFit];
frame = titleLbl.frame;
frame.origin.y = baseOffset;
//Get any change in size from the label
offset = titleLbl.frame.size.height - offset;
frame = imageView.frame;
frame.origin.y = frame.origin.y + offset;
self.imageView.frame = frame;
frame = photosBtn.frame;
frame.origin.y = frame.origin.y + offset;
[self.photosBtn setFrame:frame];
frame = detailLbl.frame;
frame.origin.y = frame.origin.y + offset;
self.detailLbl.frame = frame;
baseOffset = self.detailLbl.frame.origin.y;
CGFloat detailOffset = self.detailLbl.frame.size.height;
self.detailLbl.text = destObject.description;
[self.detailLbl sizeToFit];
frame = detailLbl.frame;
frame.origin.y = baseOffset;
self.detailLbl.frame = frame;
detailOffset = self.detailLbl.frame.size.height - detailOffset;
offset = offset + detailOffset;
frame = blueLine.frame;
frame.origin.y = frame.origin.y + offset;
self.blueLine.frame = frame;
self.whereToDiveLbl.font = [UIFont fontWithName:@"Avenir-Heavy" size:22];
frame = whereToDiveLbl.frame;
frame.origin.y = frame.origin.y + offset;
self.whereToDiveLbl.frame = frame;
frame = grayLine.frame;
frame.origin.y = frame.origin.y + offset;
self.grayLine.frame = frame;
frame = CGRectMake(headerView.frame.origin.x, headerView.frame.origin.y, headerView.frame.size.width, grayLine.frame.size.height + grayLine.frame.origin.y + 5);
self.headerView.frame = frame;
}
我试过四处寻找类似的问题,但找不到任何问题。任何人都可以对此有所了解吗?
我应该指出 UIView 本身(即本例中的 headerView)确实反映了模拟器上对其框架的更改,但它的子视图没有。如果它有任何区别,我启用了自动调整子视图,但我启用或禁用了相同的结果。