Created
April 7, 2017 01:12
-
-
Save matoelorriaga/dfe84393e258542f83883fac1c33f41d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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