久久久久久久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)
主站蜘蛛池模板: 日韩欧美一区二区三区 | 国产精品夜夜夜一区二区三区尤 | 亚洲精品一区在线 | 黄色一级大片在线免费看产 | 亚洲国产成人精品久久久国产成人一区 | 99成人精品| 日本一区二区高清不卡 | 天天夜夜操 | www国产成人免费观看视频,深夜成人网 | 欧美久久综合 | 亚洲成人一区二区在线 | 日韩在线一区二区 | 日本在线小视频 | 午夜免费网 | 秋霞国产| 久久精品亚洲 | 一二区视频 | 成人无遮挡毛片免费看 | 国产精品久久久久久福利一牛影视 | 91在线观看视频 | 精品亚洲一区二区 | 日韩精品久久一区 | 国内自拍视频在线观看 | 日韩中文字幕一区二区 | 亚洲一区二区免费视频 | 国产精品毛片无码 | 国产精久久久久久久妇剪断 | 日韩视频一区二区 | 欧美高清视频一区 | 久久新| 国产成人精品在线 | 久久综合av| 精品一区二区三区在线观看国产 | 国产综合久久 | 午夜免费看视频 | 久久久久久国产 | 久久久久国产一区二区三区四区 | 日本成年免费网站 | 在线观看视频中文字幕 | 成人在线视频免费播放 | 欧美日韩国产高清 |