我试图将 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模板网!
如何继承 UIScrollView 并使委托属性私有How to subclass UIScrollView and make the delegate property private(如何继承 UIScrollView 并使委托属性私有)
Swift - 如何从照片库中获取最后拍摄的 3 张照片Swift - how to get last taken 3 photos from photo library?(Swift - 如何从照片库中获取最后拍摄的 3 张照片?)
以编程方式设置 contentOffset 触发 scrollViewDidScrolSetting contentOffset programmatically triggers scrollViewDidScroll(以编程方式设置 contentOffset 触发 scrollViewDidScroll)
使用 pagingEnabled 的 UIScrollView 中页面之间的照片应Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中页面之间的照片应用程序式间隙
为什么 UIScrollView 在 ios 6 和 ios 7 中从顶部留下空why UIScrollView is leaving space from top in ios 6 and ios 7(为什么 UIScrollView 在 ios 6 和 ios 7 中从顶部留下空间)
UIScrollView 在滚动时暂停 NSTimerUIScrollView pauses NSTimer while scrolling(UIScrollView 在滚动时暂停 NSTimer)