【发布时间】:2014-04-01 17:43:27
【问题描述】:
各位,
我有一个包含多个信息的配置文件视图。其中一些不必设置,例如传记。因此,根据它的设置,我想隐藏传记视图(结帐截图)并重新定位 UserData 视图和 ActivityData 视图并更改其超级视图的大小以填充传记视图所产生的空间。
这是我的 TableViewHeader 的实际结构:
我必须关心的另一点是,UILabel 必须是多行的并适合其内容。
所以我的问题:
- 如何重新定位 UserData 和 ActivityData 视图以填充 隐藏的 BiografieView 创造的空间?
- 如何制作传记 视图高度适合 UILabel 文本吗?
请记住,我使用的是自动布局。所以我必须使用约束来修改位置吗?
说实话.. 基本上它应该像 Instagram 一样,添加一个传记。我希望我说清楚了我想要什么..
编辑 1
我已经尝试过您的建议 Damien,但没有任何改变:
NSLog(@"Height %f, Width %f", self.labelBiografie.frame.size.height, self.labelBiografie.frame.size.width);
if ([self.profileUser objectForKey:kGSUserBiografieKey]) {
self.labelBiografie.text = [self.profileUser objectForKey:kGSUserBiografieKey];
[self.labelBiografie sizeToFit];
}else{
[self.labelBiografie setHidden:YES];
[self.countContainer setConstraintConstant:-self.labelBiografie.frame.size.height forAttribute:NSLayoutAttributeCenterY];
[self.tableHeaderViewChildVIew setConstraintConstant:-self.labelBiografie.frame.size.height forAttribute:NSLayoutAttributeHeight];
self.tableView.tableHeaderView = self.tableHeaderViewChildVIew;
}
编辑 2:
使用这个项目 (UIView-UpdateAutoLayoutConstraints ) 我在方法上遇到以下错误:
第 56 行:[self hideView:hidden byAttribute:NSLayoutAttributeHeight];
第 85 行:[self setConstraintConstant:0 forAttribute:attribute];
第 23 行:
[self.superview addConstraint: [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:constant]];
错误:
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x8c1b8e0 V:|-(0)-[UIButton:0x8c6fb40] (Names: '|':UIView:0x8c6f630 )>",
"<NSLayoutConstraint:0x8c19dc0 V:[UIButton:0x8c6fb40(100)]>",
"<NSLayoutConstraint:0x8c1d740 V:[UIButton:0x8c6fb40]-(NSSpace(8))-[UILabel:0x8c70900]>",
"<NSLayoutConstraint:0x8c20df0 V:[UILabel:0x8c70900]-(NSSpace(8))-[UIView:0x8c16a00]>",
"<NSLayoutConstraint:0x8c20fa0 V:[UIView:0x8c16a00(40)]>",
"<NSLayoutConstraint:0x8c23790 V:[UIView:0x8c16a00]-(0)-| (Names: '|':UIView:0x8c6f630 )>",
"<NSAutoresizingMaskLayoutConstraint:0x8c78e60 h=--& v=--& V:[UIView:0x8c6f630(217)]>",
"<NSLayoutConstraint:0x8c5d000 V:[UILabel:0x8c70900(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x8c20df0 V:[UILabel:0x8c70900]-(NSSpace(8))-[UIView:0x8c16a00]>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
这个错误显示在开箱即用的演示项目上,在我的项目上,当我隐藏视图时它也会返回..
【问题讨论】:
标签: ios objective-c ios7 autolayout