我有一个tableView,它有一个自定义inputAccessoryView,而tableView.keyboardDismissMode设置为.interactive。我将UIView子类化,并将这个类创建为我的自定义inputAccessoryView。
视图中有一个textView,我让它自动调整大小,直到达到一定数量的行为止。这是我的密码:
override var intrinsicContentSize: CGSize {
DispatchQueue.main.async {
let path = IndexPath(row: self.tableView.numberOfRows(inSection: 0) - 1, section: 0)
self.tableView.scrollToRow(at: path, at: .bottom, animated: true)
}
sendButton.frame.origin.y = self.frame.maxY - 5 - sendButton.frame.height
return CGSize(width: self.bounds.width, height: (textView.numberOfLines() < 10 ? textView.text.sizeForWidth(width: textView.frame.width, font: textView.font!).height : 254) + textView.frame.origin.y * 2)
}
func textViewDidChange(_ textView: UITextView) {
placeholderLabel.isHidden = !textView.text.isEmpty
if textView.numberOfLines() < 10 { // I defined numberOfLines() elsewhere
textView.isScrollEnabled = false
} else {
textView.isScrollEnabled = true
}
invalidateIntrinsicContentSize()
}.async {}块用于在tableView高度增加后再次滚动到tableView的底部。
我的问题是,当我在tableView上向下拖动以隐藏键盘时,tableView运行滚动动画( async块中的滚动动画),而我不希望它滚动到底部。下面是正在发生的事情的录象。
几天来,我一直在努力让这件事按我想要的方式运作。有谁能向我解释一下,为什么它不像我想要的那样工作,我如何才能修复它?
提前谢谢!
发布于 2016-12-03 20:06:08
我自己解决了问题!万岁!
为此,我在ViewController中创建了一个公共值,用于当前正在拖动/滚动的tableView。我使用UIScrollView委托方法来设置当前正在滚动的tableView:
scrollViewWillBeginDragging(_:)
and
scrollViewDidEndDragging(_:)然后,我将intrinsicContentSize更改为:
override var intrinsicContentSize: CGSize {
if viewController.isDragging == false && textView.isFirstResponder {
DispatchQueue.main.async {
let path = IndexPath(row: self.tableView.numberOfRows(inSection: 0) - 1, section: 0)
self.tableView.scrollToRow(at: path, at: .bottom, animated: true)
}
}
sendButton.frame.origin.y = self.frame.maxY - 5 - sendButton.frame.height
return CGSize(width: self.bounds.width, height: (textView.numberOfLines() < 10 ? textView.text.sizeForWidth(width: textView.frame.width, font: textView.font!).height : 254) + textView.frame.origin.y * 2)
}https://stackoverflow.com/questions/40950828
复制相似问题