ScrollViewContainer.swift 544 B

1234567891011121314151617181920212223242526
  1. //
  2. // ScrollViewContainer.swift
  3. // Mastodon
  4. //
  5. // Created by sxiaojian on 2021/2/7.
  6. //
  7. import UIKit
  8. protocol ScrollViewContainer: UIViewController {
  9. var scrollView: UIScrollView { get }
  10. func scrollToTop(animated: Bool)
  11. }
  12. extension ScrollViewContainer {
  13. func scrollToTop(animated: Bool) {
  14. scrollView.scrollToTop(animated: animated)
  15. }
  16. }
  17. extension UIScrollView {
  18. func scrollToTop(animated: Bool) {
  19. scrollRectToVisible(CGRect(origin: .zero, size: CGSize(width: 1, height: 1)), animated: animated)
  20. }
  21. }