久久久久久久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级毛片在线看 | 欧美精品综合在线 | 欧美在线一区视频 | 国产一区2区| 毛片免费视频 | 男人的天堂中文字幕 | 伊人伊人伊人 | 亚洲精品在线播放 | 国产伦精品一区二区 | 国产精品久久久久久久久久妇女 | 成人av免费 | 欧美韩一区二区 | 国产免费观看视频 | 国产精品久久久久aaaa | 国产亚洲欧美在线 | 插插宗合网 | jdav视频在线观看免费 | 欧美日韩高清一区 | 精品福利在线 | 欧美一区二区三区小说 | 国产精品久久久久久久久免费软件 | 在线免费观看黄色 | 欧美成人免费在线 | 久久久久久毛片免费观看 | 天天摸天天干 | 成人国产精品久久 | 欧美精品二区 | 国产激情一区二区三区 | 99成人 | 精品三级在线观看 | 天天舔天天 | 久久久av| 国产成人一区二区 | 欧美一区二区三区在线视频 | 免费观看毛片 |