I have a tableView, which auto locates back at indexPath after user has dragged it.
In other words, bouncing the tableView back into its bounds, after user dragged it out.
Here is the code:
// ...
var tracking = false
var currentPath = 0
@objc func updateRecorder(_ timer: Timer){
currentPath = somethingCalculated
}
// ...
extension ViewController: UITableViewDelegate{
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
// when the scene is in a special state
tracking = true
}
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// when the scene is in the same special state
if tracking == true{
tracking = false
scrollToRow(at: IndexPath(row: currentPath, section: 0), at: UITableView.ScrollPosition.middle, animated: true)
}
}
}
In fact, it is a music tracking app. People sing a song, the lyric tableView tracks the voice, and it auto scrolls to current line.
When tracking, and people scrolls by hand, the lyric tableView should bounces back to it ought to be.
The code above works.
Any other ideas?