ios - UITextView滚动指示器问题

标签 ios swift uitextview

我的UITextView在达到一定行数后变得可滚动。当我向上滚动一段文本时,滚动指示器不会滚动到 UITextView 的顶部,而是滚动到文本容器的顶部。有什么建议吗?

这是我的UITextView代码:

lazy var chatTextField: UITextView = {

    let chatText = UITextView()
    chatText.scrollIndicatorInsets.top = 0

    chatText.contentInset = UIEdgeInsetsMake(-40, 0, 0, 0)
    chatText.delegate = self
    chatText.backgroundColor = UIColor.clearColor()
    chatText.font = UIFont(name: "Arial", size: 16)
    chatText.textColor = UIColor(r: 120, g: 128, b: 125)
    chatText.translatesAutoresizingMaskIntoConstraints = false
    return chatText
}()

注意滚动指示器;它应该插入顶部。

enter image description here

最佳答案

我使用collectionView,这些代码行对我有用。尝试:

dispatch_async(dispatch_get_main_queue(), {self.collectionView!.reloadData()
                    let indexPath = NSIndexPath(forItem: self.messages.count-1, inSection: 0)
                        self.collectionView?.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)
                    })

关于ios - UITextView滚动指示器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304594/

相关文章:

ios - 如何使用 Realm 和 Swift 从 TableView 中删除一个部分和一行?

swift - 如何将Apple Watch设置为防水模式?

swift - 无法转换类型 'NSAttributedString.DocumentAttributeKey' 的值, "DocumentReadingOptionKey"也不起作用

iphone - 如何将 UITextView 的 "delegate"导出连接到实现 UITextViewDelegate 协议(protocol)的类?

ios - 更改 uitextview 超链接颜色

ios - 委托(delegate)不存在,EXC_BAD_ACCESS

ios - 从 Core Data 中将一对多显示为一对一

ios - 如何使用结构化模型层在 Siesta 中实现持久缓存

ios - 将组件放置在 UITextView 下方并调整大小以适合

ios - XCode Instruments 6(到目前为止)没有反射(reflect)正确的内存量