【发布时间】:2015-11-30 01:51:07
【问题描述】:
我遇到了自动布局的问题,似乎无法找到应该很容易实现的答案。
我有以下视图层次结构:
-UIScrollview
-UIView
- UILabel
- UILabel
- UILabel
标签上的前导/尾随约束使它们在更薄的设备(iPhone 4s 与 iPhone 6)上更高。
为了让 UIScrollview 正常工作,我需要在 UIScrollView 内部设置 UIView 的高度约束,以避免“模糊高度”警告。
但在 iPhone 4s 上运行时,UIView 不够高,无法容纳其子视图。
到目前为止,我唯一的解决方案是在 UIView 上创建对高度约束的引用,并在视图出现时更新高度约束:
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.contentHeight.constant =self.lastLabel.frame.origin.y+ self.lastLabel.frame.size.height;
[self.view layoutIfNeeded];
}
我认为必须有更好的方法来做如此简单的事情。
我附上了一张图片来详细说明问题。
感谢您的宝贵时间。
根据下面的@Katty,使宽度/高度等于滚动视图的超级视图会导致更大的问题:
【问题讨论】:
标签: ios objective-c iphone uiscrollview autolayout