【发布时间】:2016-03-23 16:42:00
【问题描述】:
我在这里经历了很多线程并尝试了两个最推荐的解决方案。 ViewDidLoad() 方法内部:
self.darkBackgroundWithButtons.frame = CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height * 0.254)
或
self.darkBackgroundWithButtons.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height * 0.254)
另外,在我的故事板中,我将视图的高度约束设置为低优先级 (如果我没有在情节提要中设置高度,xcode 会抱怨布局不明确)
但是上面的这些代码行都没有对darkBackgroundWithButtons做任何事情,它对于每个设备尺寸都保持相同的高度
【问题讨论】:
-
如果您使用自动布局,您应该在视图控制器的
viewwilllayoutsubviews或viewDidAppear方法中设置框架 -
您需要通过更改您给它的高度约束的
constant来设置高度。如果您使用自动布局,则无法直接更改框架 -
@dan 你能提供更多细节我应该做什么吗?
标签: ios swift uiview autolayout