質問編集履歴
1
より詳しく修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,15 +2,163 @@
|
|
2
2
|
|
3
3
|
原因がわからない状態です。
|
4
4
|
|
5
|
+
|
6
|
+
|
5
7
|
```
|
8
|
+
|
9
|
+
// MARK: - UIScrollViewDelegate
|
10
|
+
|
11
|
+
|
6
12
|
|
7
13
|
extension TabView: UICollectionViewDelegate {
|
8
14
|
|
9
|
-
func scrollViewDidEndScrollingAnimation(_ scrollView:UIScrollView){
|
10
15
|
|
16
|
+
|
17
|
+
func scrollViewDidScroll(scrollView: UIScrollView) {
|
18
|
+
|
19
|
+
|
20
|
+
|
11
|
-
|
21
|
+
if scrollView.dragging {
|
22
|
+
|
23
|
+
currentBarView.hidden = true
|
24
|
+
|
25
|
+
let indexPath = NSIndexPath(forItem: currentIndex, inSection: 0)
|
26
|
+
|
27
|
+
if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? TabCollectionCell {
|
28
|
+
|
29
|
+
cell.showCurrentBarView()
|
12
30
|
|
13
31
|
}
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
guard isInfinity else {
|
38
|
+
|
39
|
+
return
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
if pageTabItemsWidth == 0.0 {
|
46
|
+
|
47
|
+
pageTabItemsWidth = floor(scrollView.contentSize.width / 3.0)
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
if (scrollView.contentOffset.x <= 0.0) || (scrollView.contentOffset.x > pageTabItemsWidth * 2.0) {
|
54
|
+
|
55
|
+
scrollView.contentOffset.x = pageTabItemsWidth
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
func scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
|
66
|
+
|
67
|
+
// Accept the touch event because animation is complete
|
68
|
+
|
69
|
+
updateCollectionViewUserInteractionEnabled(true)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
guard isInfinity else {
|
74
|
+
|
75
|
+
return
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
let indexPath = NSIndexPath(forItem: currentIndex, inSection: 0)
|
82
|
+
|
83
|
+
if shouldScrollToItem {
|
84
|
+
|
85
|
+
// After the moved so as not to sense of incongruity, to adjust the contentOffset at the currentIndex
|
86
|
+
|
87
|
+
collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .CenteredHorizontally, animated: false)
|
88
|
+
|
89
|
+
shouldScrollToItem = false
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
func moveCurrentBarView(indexPath: NSIndexPath, animated: Bool, shouldScroll: Bool) {
|
102
|
+
|
103
|
+
if shouldScroll {
|
104
|
+
|
105
|
+
collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .CenteredHorizontally, animated: animated)
|
106
|
+
|
107
|
+
layoutIfNeeded()
|
108
|
+
|
109
|
+
collectionViewContentOffsetX = 0.0
|
110
|
+
|
111
|
+
currentBarViewWidth = 0.0
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
if let cell = collectionView.cellForItemAtIndexPath(indexPath) as? TabCollectionCell {
|
116
|
+
|
117
|
+
currentBarView.hidden = false
|
118
|
+
|
119
|
+
if animated && shouldScroll {
|
120
|
+
|
121
|
+
cell.isCurrent = true
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
cell.hideCurrentBarView()
|
126
|
+
|
127
|
+
currentBarViewWidthConstraint.constant = cell.frame.width
|
128
|
+
|
129
|
+
if !isInfinity {
|
130
|
+
|
131
|
+
currentBarViewLeftConstraint?.constant = cell.frame.origin.x
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
UIView.animateWithDuration(0.2, animations: {
|
136
|
+
|
137
|
+
self.layoutIfNeeded()
|
138
|
+
|
139
|
+
}, completion: { _ in
|
140
|
+
|
141
|
+
if !animated && shouldScroll {
|
142
|
+
|
143
|
+
cell.isCurrent = true
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
if !self.isInfinity {
|
148
|
+
|
149
|
+
self.updateCollectionViewUserInteractionEnabled(true)
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
})
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
beforeIndex = currentIndex
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
14
162
|
|
15
163
|
```
|
16
164
|
|