forked from WenchaoD/FSPagerView
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSPagerCollectionView.swift
64 lines (55 loc) · 1.68 KB
/
FSPagerCollectionView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// FSPagerViewCollectionView.swift
// FSPagerView
//
// Created by Wenchao Ding on 24/12/2016.
// Copyright © 2016 Wenchao Ding. All rights reserved.
//
// 1. Reject -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary]
// 2. Group initialized features
import UIKit
class FSPagerViewCollectionView: UICollectionView {
fileprivate weak var pagerView: FSPagerView? {
return self.superview?.superview as? FSPagerView
}
#if !os(tvOS)
override var scrollsToTop: Bool {
set {
super.scrollsToTop = false
}
get {
return false
}
}
#endif
override var contentInset: UIEdgeInsets {
set {
super.contentInset = .zero
if (newValue.top > 0) {
let contentOffset = CGPoint(x:self.contentOffset.x, y:self.contentOffset.y+newValue.top);
self.contentOffset = contentOffset
}
}
get {
return super.contentInset
}
}
override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
super.init(frame: frame, collectionViewLayout: layout)
self.commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
}
fileprivate func commonInit() {
self.contentInset = .zero
self.decelerationRate = UIScrollViewDecelerationRateFast
self.showsVerticalScrollIndicator = false
self.showsHorizontalScrollIndicator = false
#if !os(tvOS)
self.scrollsToTop = false
self.isPagingEnabled = false
#endif
}
}