问题描述
我想以编程方式更改 UITextView 的高度约束,因此我将约束设置为控制器中的插座,如下所示:
I want to change the height constraint of a UITextView programmatically so I set the constraint as an outlet in my controller like this:
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *descriptionHeightConstraint;
要更改它,我执行以下操作:
To change it I do the following:
self.descriptionHeightConstraint.constant = self.description.contentSize.height;
如果我在 viewDidAppear 中执行此操作,但问题是我可以看到显示视图后高度如何变化,这对用户不是很友好,所以我尝试在 中执行此操作>viewWillAppear 但没有在那里工作,高度没有改变.更改约束后调用 setNeedsUpdateConstraints 也不起作用.
This works if I do it in viewDidAppear but the problem with this is that I can see how the height changes after the view displayed which is not very user friendly so I tried doing it in viewWillAppear but didn't work there, the height doesn't change. Calling setNeedsUpdateConstraints after changing the constraint didn't work either.
为什么在 viewDidAppear 中工作而不在 viewWillAppear 中工作?有什么解决方法吗?
Why is working in viewDidAppear and not in viewWillAppear? Any workaround?
提前致谢!
推荐答案
尝试在 viewDidLayoutSubviews 中设置常量.
Try setting the constant in viewDidLayoutSubviews instead.
请注意,使用文本视图的 contentSize 属性设置文本视图的高度在 iOS 7 中不起作用.请参阅 https://stackoverflow.com/a/18837714/1239263
Note that using the text view's contentSize property to set the text view's height does not work in iOS 7. See https://stackoverflow.com/a/18837714/1239263
这篇关于以编程方式更改高度约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)