UITableView.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // UITableView.swift
  3. // Mastodon
  4. //
  5. // Created by Cirno MainasuK on 2021-3-2.
  6. //
  7. import UIKit
  8. import MastodonAsset
  9. import MastodonLocalization
  10. extension UITableView {
  11. func deselectRow(with transitionCoordinator: UIViewControllerTransitionCoordinator?, animated: Bool) {
  12. guard let indexPathForSelectedRow = indexPathForSelectedRow else { return }
  13. guard let transitionCoordinator = transitionCoordinator else {
  14. deselectRow(at: indexPathForSelectedRow, animated: animated)
  15. return
  16. }
  17. transitionCoordinator.animate(alongsideTransition: { _ in
  18. self.deselectRow(at: indexPathForSelectedRow, animated: animated)
  19. }, completion: { context in
  20. if context.isCancelled {
  21. self.selectRow(at: indexPathForSelectedRow, animated: animated, scrollPosition: .none)
  22. }
  23. })
  24. }
  25. func blinkRow(at indexPath: IndexPath) {
  26. DispatchQueue.main.asyncAfter(wallDeadline: .now() + 1) { [weak self] in
  27. guard let self = self else { return }
  28. guard let cell = self.cellForRow(at: indexPath) else { return }
  29. let backgroundColor = cell.backgroundColor
  30. UIView.animate(withDuration: 0.3) {
  31. cell.backgroundColor = Asset.Colors.brand.color.withAlphaComponent(0.5)
  32. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  33. UIView.animate(withDuration: 0.3) {
  34. cell.backgroundColor = backgroundColor
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }