在我看来,这是一个自动调整大小的问题。您需要将标签和文本字段的自动调整大小设置为
UIViewAutoresizingFlexibleHeight 和 UIViewAutoresizingFlexibleTopMargin
我建议您将这些标签和文本字段放在具有相同自动调整大小属性的“内容”视图中,并将其添加为子视图。
编辑:(添加示例)
UIView *contentView = [[UIView alloc] initWithFrame:frame]; //contentView's initail frame.
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:contentView.bounds]; //in this example the label takes the whole frame of the contentView, you can change it to be smaller in height if it suits you purpose.
descriptionLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin;
contentView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;
点击“+”按钮:
[UIView animateWithDuration:0.2f animations:^{
CGRect rect = contentView.frame;
rect.size.height = 200;
contentView.frame = rect;
}];
点击“-”按钮:
[UIView animateWithDuration:0.2f animations:^{
CGRect rect = contentView.frame;
rect.size.height = 100;
contentView.frame = rect;
}];