FSPagerCollectionView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // FSPagerCollectionView.swift
  3. // FSPagerView
  4. //
  5. // Created by Wenchao Ding on 24/12/2016.
  6. // Copyright © 2016 Wenchao Ding. All rights reserved.
  7. //
  8. // 1. Reject -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary]
  9. // 2. Group initialized features
  10. import UIKit
  11. class FSPagerCollectionView: UICollectionView {
  12. #if !os(tvOS)
  13. override var scrollsToTop: Bool {
  14. set {
  15. super.scrollsToTop = false
  16. }
  17. get {
  18. return false
  19. }
  20. }
  21. #endif
  22. override var contentInset: UIEdgeInsets {
  23. set {
  24. super.contentInset = .zero
  25. if (newValue.top > 0) {
  26. let contentOffset = CGPoint(x:self.contentOffset.x, y:self.contentOffset.y+newValue.top);
  27. self.contentOffset = contentOffset
  28. }
  29. }
  30. get {
  31. return super.contentInset
  32. }
  33. }
  34. override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
  35. super.init(frame: frame, collectionViewLayout: layout)
  36. self.commonInit()
  37. }
  38. required init?(coder aDecoder: NSCoder) {
  39. super.init(coder: aDecoder)
  40. self.commonInit()
  41. }
  42. fileprivate func commonInit() {
  43. self.contentInset = .zero
  44. self.decelerationRate = UIScrollView.DecelerationRate.fast
  45. self.showsVerticalScrollIndicator = false
  46. self.showsHorizontalScrollIndicator = false
  47. if #available(iOS 10.0, *) {
  48. self.isPrefetchingEnabled = false
  49. }
  50. if #available(iOS 11.0, *) {
  51. self.contentInsetAdjustmentBehavior = .never
  52. }
  53. #if !os(tvOS)
  54. self.scrollsToTop = false
  55. self.isPagingEnabled = false
  56. #endif
  57. }
  58. }