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

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

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

問(wèn)題描述

我試圖將 UITextView 放置在帶有 AutoLayout 的 UIScrollView 中,但沒(méi)有成功.我試過(guò)的是,

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è)置了一個(gè)文本(很多會(huì)導(dǎo)致滾動(dòng)的文本)
  • 我用下面的代碼設(shè)置了 UITextView 的高度約束.在 viewDidLoad() 和 viewDidLayoutSubviews() 中設(shè)置文本后,我已經(jīng)嘗試過(guò)了,但沒(méi)有成功

self.textViewHeightConstraint.constant = [self.textView sizeThatFits:CGSizeMake(self.textView.frame.size.width, FLT_MAX)].height;

UITextView 正在達(dá)到它的高度,但 UIScrollView 沒(méi)有.有什么我錯(cuò)過(guò)的嗎?

UITextView is getting its height, but UIScrollView isn't. Is there anything I've missed?

推薦答案

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

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

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

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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 - 如何從照片庫(kù)中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁(yè)面之間的照片應(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 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 久久777 | 午夜三级在线观看 | 日韩在线视频网址 | 国产一区二区三区久久 | 欧美综合国产精品久久丁香 | 8x国产精品视频一区二区 | 亚洲欧美综合 | 99热在线免费 | 亚洲在线观看视频 | 一区二区三区四区av | 中文字字幕一区二区三区四区五区 | 日韩欧美久久精品 | 中文字幕二区 | 天堂综合网 | 欧美日韩久久精品 | 国产一级片免费视频 | 草久久免费视频 | 成人小视频在线观看 | 97精品国产一区二区三区 | 精品久久久久久久久久 | 国产精品99久久久久久宅男 | 日本精品视频一区二区三区四区 | 精品视频一区二区三区在线观看 | 亚洲理论在线观看电影 | 天天操精品视频 | 视频一区中文字幕 | 免费观看毛片 | 国产高清视频一区二区 | 亚洲手机视频在线 | 久久香蕉精品视频 | 性高湖久久久久久久久3小时 | 草草视频在线免费观看 | 欧美精品一区二区三区在线 | 日韩av免费在线电影 | 亚洲午夜av久久乱码 | 色av一区二区三区 | 99精品视频免费在线观看 | 中文一区 | 欧日韩在线观看 | 九九成人 | 中文字幕成人 |