import UIKitclass VIEwController: UIVIEwController,UITextVIEwDelegate {@IBOutlet weak var messageTextVIEw: UITextVIEw!let messageTextVIEwMaxHeight: CGfloat = 100overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() self.messageTextVIEw.delegate = self}func textVIEwDIDChange(textVIEw: UITextVIEw) { if textVIEw.frame.size.height >= self.messageTextVIEwMaxHeight { textVIEw.scrollEnabled = true textVIEw.frame.size.height = self.messageTextVIEwMaxHeight } else { textVIEw.scrollEnabled = false }}}解决方法 看来你的代码需要两个更改,它会正常工作.
>取代最小约束高度,提供最大高度100:
>更改代码如下:
import UIKitclass VIEwController: UIVIEwController,UITextVIEwDelegate{ @IBOutlet weak var messageTextVIEw: UITextVIEw! let messageTextVIEwMaxHeight: CGfloat = 100 overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() messageTextVIEw.delegate = self } func textVIEwDIDChange(textVIEw: UITextVIEw) { if textVIEw.contentSize.height >= self.messageTextVIEwMaxHeight { textVIEw.scrollEnabled = true } else { textVIEw.frame.size.height = textVIEw.contentSize.height textVIEw.scrollEnabled = false // textVIEw.isScrollEnabled = false for swift 4.0 } }}总结
以上是内存溢出为你收集整理的ios – 如何动态地将TextView高度更改为阈值,然后允许滚动?全部内容,希望文章能够帮你解决ios – 如何动态地将TextView高度更改为阈值,然后允许滚动?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)