为什么我不能在Swift中更改视图的帧大小? [英] Why can't I change the view's frame size in Swift?
问题描述
所以这是我遇到过的最奇怪的事情。
So this is the weirdest thing I came across ever.
我添加一个简单的 UIView
UIViewController
上的 UIView
。我将大小更改为200 x 200然后我想通过将此行代码放在 viewDidLoad $中来更改
UIView
的大小c $ c>方法:
I add a simple UIView
on top of an UIView
on an UIViewController
. I change the size to 200 x 200 and then I want to change the UIView
's size by placing this line of code inside the viewDidLoad
method:
self.gameBackgroundView.frame.size.height = 10
这在Swift看来完全正常。虽然没有任何反应。我可以改变颜色,角半径等...
which seems perfectly normal in Swift. Though, nothing happens. I can change the color, corner radius etc...
编辑:
我还删除了所有约束从那个视图,它仍然无法正常工作。
I have also deleted all constraints from that view and it still does not work.
推荐答案
好的,所以我在堆栈上找到了解决方案..
Ok, So I found a solution here on stack ..
正确的答案,有效的是:
The correct answer, that works is, that:
- I需要创建我的heightConstraint的IBOutlet
- 相应地更改该约束的值
谢谢大家好!
这篇关于为什么我不能在Swift中更改视图的帧大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!