Skip to content

Instantly share code, notes, and snippets.

@matoelorriaga
Created April 7, 2017 01:12
Show Gist options
  • Save matoelorriaga/dfe84393e258542f83883fac1c33f41d to your computer and use it in GitHub Desktop.
Save matoelorriaga/dfe84393e258542f83883fac1c33f41d to your computer and use it in GitHub Desktop.
import UIKit
extension UIViewController {
func smoothlyDeselectRows(tableView: UITableView?) {
let selectedIndexPaths = tableView?.indexPathsForSelectedRows ?? []
if let coordinator = transitionCoordinator {
coordinator.animateAlongsideTransition(in: parent?.view, animation: { context in
selectedIndexPaths.forEach {
tableView?.deselectRow(at: $0, animated: context.isAnimated)
}
}, completion: { context in
if context.isCancelled {
selectedIndexPaths.forEach {
tableView?.selectRow(at: $0, animated: false, scrollPosition: .none)
}
}
})
} else {
selectedIndexPaths.forEach {
tableView?.deselectRow(at: $0, animated: false)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment