正在重置 UIView 布局 [英] UIView layout being reset
问题描述
我正在使用故事板来创建我的 view
的初始状态.然后我有一个 button
改变布局(它扩展一个 UITextView
以占据屏幕的一半).
I am using a storyboard to create the initial state of my view
. I then have a button
that changes the layout (it expands a UITextView
to take up half of the screen).
每当我尝试以编程方式更改屏幕上标签的文本时,UIView
就会重置为故事板布局.
Whenever I try to alter the text of a label on the screen programatically the UIView
is resetting to the storyboard layout.
是否有一种方法可以将 UIView
重置为导致这种情况发生的初始状态?或者任何想法为什么会发生这种情况?
Is there a method that resets a UIView
to its initial state that is causing this to happen? Or any ideas why this is occurring?
推荐答案
您为故事板启用了自动布局.自动布局系统将(在不同时间)根据故事板中的布局约束设置视图层次结构中每个视图的位置和大小.
You have autolayout turned on for your storyboard. The autolayout system will (at various times) set the position and size of every view in your view hierarchy based on the layout constraints in your storyboard.
您可以关闭故事板中的自动布局,或者您可以通过修改其布局约束来调整文本视图的大小.
You can either turn off autolayout in your storyboard, or you can resize the text view by modifying its layout constraints.
如果您想使用自动布局并修改约束,请至少观看 WWDC 2012 中这三个视频中的第一个:
If you want to use autolayout and modify the constraints, watch at least the first of these three videos from WWDC 2012:
这篇关于正在重置 UIView 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!