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

帶有自動布局的 UIScrollView 內(nèi)的 UITextView

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

問題描述

我試圖將 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 上設(shè)置了約束(前導(dǎo)、尾隨、頂部、底部)
  • 我在 UITextView 上設(shè)置了約束(頂部、前導(dǎo)、尾部、高度)
  • 我創(chuàng)建了 UITextView 高度約束的 IBOutlet
  • 我在 viewDidLoad() 中的 UITextView 上設(shè)置了一個文本(很多會導(dǎo)致滾動的文本)
  • 我用下面的代碼設(shè)置了 UITextView 的高度約束.在 viewDidLoad() 和 viewDidLayoutSubviews() 中設(shè)置文本后,我已經(jīng)嘗試過了,但沒有成功

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?

推薦答案

經(jīng)過幾天的研究和接觸 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 內(nèi)添加 UITextView(步驟 2 中添加的視圖)
  4. 確保 UITextView 的啟用滾動"未選中
  5. 在 UIScrollView 上添加 4 個約束(前導(dǎo)、尾隨、頂部、底部)
  6. 在 UIView(步驟 2 中添加的視圖)上添加 4 個約束(前導(dǎo)、尾隨、頂部、底部)
  7. 在 UIView(第 2 步中添加的視圖)和主視圖上添加等寬"約束
  8. 在 UITextView 上添加 5 個約束(前導(dǎo)、尾隨、頂部、底部、高度).完成此步驟后,您不應(yīng)收到任何有關(guān)約束的錯誤和警告.
  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 和內(nèi)部的 UITextView,并且會很開心.

After all of these 10 steps, you'll get fully working UIScrollView with UITextView inside and be happy.

這篇關(guān)于帶有自動布局的 UIScrollView 內(nèi)的 UITextView的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

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(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應(yīng)用程序式間隙)
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)
主站蜘蛛池模板: 免费视频一区 | 国产精品福利在线 | 亚洲视频网址 | 色吧综合| 国产欧美日韩综合精品 | 国产黄网 | 五月婷婷深深爱 | 日日夜夜综合 | 日韩精品视频在线 | 欧美成人精品一区二区 | 欧美性精品 | 欧美日本国产 | 久久久久久网 | 极品尤物一区二区三区 | 亚洲精品一区二区在线观看 | 男人午夜影院 | 成人毛片一区二区三区 | 欧美一级片免费看 | 欧美区一区二 | 久久国产欧美 | 天天草天天草 | 色片在线观看 | 欧美一区二区在线视频 | 日韩在线观看一区 | 少妇一级淫片免费放 | 激情视频网 | 午夜在线影院 | 亚洲三区在线观看 | 黄色av一区 | 丁香av | 久久国产精品一区二区三区 | 福利小视频 | a级片免费在线观看 | 亚洲一级免费视频 | 中文字幕自拍偷拍 | 精品人伦一区二区三区 | 成人黄色一级片 | 亚洲另类av | 不卡在线| 成人做受黄大片 | 少妇一级淫片免费看 |