作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个文本框区域,它应该有一个灵活的高度,沿着你写的行数增长。
我想听听它的高度变化,然后当创建新行时,这个听众会说“嗨,高度已经改变了!”。
------------初始高度------------
------------ 高度变了!!! ----------
我找不到合适的方法来做到这一点,因为 swift 中的 addObserver
需要一个像 keyboardWillShow
这样的 NotificationIdentifier 而这里我没有像 heightWillChange
.
当高度改变时如何调用函数?
最佳答案
使用 UITextView
的委托(delegate)方法
var textViewHeight: CGFloat = 0
func textViewDidChange(textView: UITextView)
{
let newTextViewHeight = textView.frame.size.height
if textViewHeight != newTextViewHeight
{
print("---------- Height has changed !!! ----------")
}
textViewHeight = newTextViewHeight
}
关于ios - 如何为变化的高度添加观察者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38057589/
我是一名优秀的程序员,十分优秀!