久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有自動布局的 UIScrollView 內的 UITextView

UITextView inside UIScrollView with AutoLayout(帶有自動布局的 UIScrollView 內的 UITextView)
本文介紹了帶有自動布局的 UIScrollView 內的 UITextView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我試圖將 UITextView 放置在帶有 AutoLayout 的 UIScrollView 中,但沒有成功.我試過的是,

I am trying to place UITextView inside UIScrollView with AutoLayout with no luck. What I have tried is,

  • 我將 UIScrollView 放在 Storyboard 的主視圖中
  • 我在 Storyboard 中的 UIScrollView 中放置了 UITextView 并禁用了 Scrolling Enabled
  • 我在 UIScrollView 上設置了約束(前導、尾隨、頂部、底部)
  • 我在 UITextView 上設置了約束(頂部、前導、尾部、高度)
  • 我創建了 UITextView 高度約束的 IBOutlet
  • 我在 viewDidLoad() 中的 UITextView 上設置了一個文本(很多會導致滾動的文本)
  • 我用下面的代碼設置了 UITextView 的高度約束.在 viewDidLoad() 和 viewDidLayoutSubviews() 中設置文本后,我已經嘗試過了,但沒有成功

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.

  1. 在 Storyboard 的主視圖中添加 UIScrollView
  2. 在 UIScrollView 中添加 UIView
  3. 在 UIView 內添加 UITextView(步驟 2 中添加的視圖)
  4. 確保 UITextView 的啟用滾動"未選中
  5. 在 UIScrollView 上添加 4 個約束(前導、尾隨、頂部、底部)
  6. 在 UIView(步驟 2 中添加的視圖)上添加 4 個約束(前導、尾隨、頂部、底部)
  7. 在 UIView(第 2 步中添加的視圖)和主視圖上添加等寬"約束
  8. 在 UITextView 上添加 5 個約束(前導、尾隨、頂部、底部、高度).完成此步驟后,您不應收到任何有關約束的錯誤和警告.
  9. 在 ViewController 上添加 UITextView 高度約束 IBOutlet.@property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint; 并在 Storyboard 中連接
  10. 以編程方式更改 UITextView 高度約束.self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, CGFLOAT_MAX)].height;
  1. Add UIScrollView inside the main view in Storyboard
  2. Add UIView inside the UIScrollView
  3. Add UITextView inside the UIView (the view added in step 2)
  4. Make sure "Scrolling Enabled" of UITextView is unchecked
  5. Add 4 constraints (leading, trailing, top, bottom) on UIScrollView
  6. Add 4 constraints (leading, trailing, top, bottom) on UIView (the view added in step 2)
  7. Add "Width Equally" constraint on UIView (the view added in step 2) and the main view
  8. Add 5 constraints (leading, trailing, top, bottom, height) on UITextView. After this step you shouldn't get any errors and warnings on constraints.
  9. Add UITextView height constraint IBOutlet on the ViewController. @property (nonatomic, weak) IBOutlet NSLayoutConstraint *textViewHeightConstraint; and connect it in Storyboard
  10. Change the UITextView height constraint programmatically. self.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模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 日韩精品一区二区三区久久 | 亚洲免费观看 | 中文字幕一区二区三区精彩视频 | 亚洲精品一二区 | 欧美成人a∨高清免费观看 老司机午夜性大片 | 国产免费观看视频 | 精精国产xxxx视频在线播放7 | 91免费观看国产 | 欧美精品片| 国产真实精品久久二三区 | 农村真人裸体丰满少妇毛片 | 国产精品久久久久999 | 欧美激情va永久在线播放 | 99精品网站 | 小早川怜子xxxxaⅴ在线 | 国产一区影院 | 成人超碰 | 美女福利网站 | 久久这里有精品 | 国产视频久久久 | 在线一区| 一区二区免费视频 | 国产伦精品一区二区三区高清 | 欧美一级特黄aaa大片在线观看 | 91亚洲国产成人久久精品网站 | 成人精品视频在线观看 | 国产成人叼嘿视频在线观看 | 成人国产精品一级毛片视频毛片 | 中文字幕亚洲视频 | 欧美成人a∨高清免费观看 欧美日韩中 | 亚洲一区二区三区久久久 | 成人三级在线观看 | 国产欧美日韩精品一区 | 伊人网综合| 午夜在线电影网 | 成人小视频在线观看 | 国产精久久久久久久 | 91人人视频在线观看 | 国产区高清 | 99久久精品国产麻豆演员表 | 天天综合网永久 |