我试图将 UITextView 放置在带有 AutoLayout 的 UIScrollView 中,但没有成功.我试过的是,
I am trying to place UITextView inside UIScrollView with AutoLayout with no luck. What I have tried is,
self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, FLT_MAX)].height;
UITextView 正在达到它的高度,但 UIScrollView 没有.有什么我错过的吗?
UITextView is getting its height, but UIScrollView isn't. Is there anything I've missed?
经过几天的研究和接触 UIScrollView + UITextView + Auto Layout,我成功获得了一个完整的 UIScrollView.我想分享我的解决方案,以防有人遇到同样的情况.
After a few days of research and getting my hands dirty with UIScrollView + UITextView + Auto Layout, I successfully got a fully working UIScrollView. I want to share my solution just in case someone might stuck on the same situation.
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint;
并在 Storyboard 中连接self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint;
and connect it in Storyboardself.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;
完成所有这 10 个步骤后,您将获得完整的 UIScrollView 和内部的 UITextView,并且会很开心.
After all of these 10 steps, you'll get fully working UIScrollView with UITextView inside and be happy.
这篇关于带有自动布局的 UIScrollView 内的 UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!