@@ -11,7 +11,7 @@ import UIKit
11
11
public protocol AnimatedCardsViewDataSource : class {
12
12
func numberOfVisibleCards( ) -> Int
13
13
func numberOfCards( ) -> Int
14
- func contentForCardNumber ( number: Int , size : ( width : CGFloat , height : CGFloat ) ) -> UIView
14
+ func cardNumber ( number: Int ) -> BaseCardView
15
15
}
16
16
17
17
public class AnimatedCardsView : UIView {
@@ -71,13 +71,11 @@ public class AnimatedCardsView: UIView {
71
71
// MARK: Initializers
72
72
override init ( frame: CGRect ) {
73
73
super. init ( frame: frame)
74
- configure ( )
75
74
}
76
75
77
76
required public init ? ( coder aDecoder: NSCoder ) {
78
77
super. init ( coder: aDecoder)
79
78
backgroundColor = UIColor . yellowColor ( )
80
- configure ( )
81
79
}
82
80
83
81
// MARK: Config
@@ -127,9 +125,9 @@ public class AnimatedCardsView: UIView {
127
125
currentIndex++
128
126
129
127
let frontView = cardArray. removeFirst ( )
130
-
131
- if currentIndex + cardArray . count < cardCount {
132
- addNewCardViewWithIndex ( currentIndex , insertOnRear: true )
128
+ let lastIndex = currentIndex + cardArray . count
129
+ if lastIndex < cardCount {
130
+ addNewCardViewWithIndex ( lastIndex , insertOnRear: true )
133
131
}
134
132
135
133
UIView . animateWithDuration ( animationsSpeed*1. 5 , animations: {
@@ -163,8 +161,8 @@ extension AnimatedCardsView {
163
161
}
164
162
}
165
163
166
- cardArray = ( 0 ..< maxVisibleCardCount) . map { ( tagId ) in
167
- let view = generateNewCardViewWithTagId ( tagId )
164
+ cardArray = ( 0 ..< maxVisibleCardCount) . map { ( index ) in
165
+ let view = generateNewCardViewWithIndex ( index )
168
166
addSubview ( view)
169
167
applyConstraintsToView ( view)
170
168
return view
@@ -173,7 +171,7 @@ extension AnimatedCardsView {
173
171
174
172
private func addNewCardViewWithIndex( index: Int , insertOnRear rear: Bool = false ) -> UIView {
175
173
let newIndex = rear ? subviews. count : 0
176
- let newView = generateNewCardViewWithTagId ( index)
174
+ let newView = generateNewCardViewWithIndex ( index)
177
175
rear ? insertSubview ( newView, atIndex: newIndex) : addSubview ( newView)
178
176
rear ? cardArray. append ( newView) : cardArray. insert ( newView, atIndex: newIndex)
179
177
applyConstraintsToView ( newView)
@@ -182,21 +180,9 @@ extension AnimatedCardsView {
182
180
return newView
183
181
}
184
182
185
- private func generateNewCardViewWithTagId ( tagId : NSInteger ) -> UIView {
186
- let view = UIView ( )
183
+ private func generateNewCardViewWithIndex ( index : Int ) -> UIView {
184
+ let view = self . dataSourceDelegate! . cardNumber ( index )
187
185
view. translatesAutoresizingMaskIntoConstraints = false
188
- view. tag = tagId+ 1
189
- switch tagId {
190
- case 0 : view. backgroundColor = UIColor . purpleColor ( )
191
- case 1 : view. backgroundColor = UIColor . redColor ( )
192
- case 2 : view. backgroundColor = UIColor . blackColor ( )
193
- case 3 : view. backgroundColor = UIColor . greenColor ( )
194
- case 4 : view. backgroundColor = UIColor . brownColor ( )
195
- case 5 : view. backgroundColor = UIColor . darkGrayColor ( )
196
- case 6 : view. backgroundColor = UIColor . blueColor ( )
197
- case 7 : view. backgroundColor = UIColor . orangeColor ( )
198
- default : view. backgroundColor = UIColor . whiteColor ( )
199
- }
200
186
return view
201
187
}
202
188
0 commit comments