【发布时间】:2019-05-10 10:11:58
【问题描述】:
我花了很多时间来找出这个错误。在开始滚动 看起来不错,但不时滚动增加自动 人类无法阅读。如何保持滚动与开始一样。
var start_index = 0
var dest_index = 0 //approximately 300
var timer = Timer()
var falagisTrue : Bool?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
dest_index = newsViewModels.count
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.keepScrolling), userInfo: nil, repeats: true)
}
@objc func keepScrolling(){
if start_index > dest_index - 2{
timer.invalidate()
}else{
if (falagisTrue ?? false || falagisTrue == nil) {
falagisTrue = false
start_index += 1
UIView.animate(withDuration: 10, delay: 0, options: [], animations: {
let Index = IndexPath(row: self.start_index, section: 0)
self.tableView.scrollToRow(at:Index, at: .top, animated: false)
}) { finished in
self.falagisTrue = true
}
}
}
}
请您帮我修复这个错误或提供任何替代解决方案以保持自动滚动?
【问题讨论】:
标签: swift uitableview smooth-scrolling