@@ -16,11 +16,7 @@ public protocol AnimatedCardsViewDataSource : class {
16
16
17
17
public class AnimatedCardsView : UIView {
18
18
19
- private var cardArray : [ UIView ] ! = [ ]
20
- private lazy var gestureRecognizer : UIPanGestureRecognizer = {
21
- return UIPanGestureRecognizer ( target: self , action: " scrollOnView: " )
22
- } ( )
23
-
19
+ // MARK: Public properties
24
20
public weak var dataSourceDelegate : AnimatedCardsViewDataSource ? {
25
21
didSet {
26
22
if dataSourceDelegate != nil {
@@ -38,16 +34,21 @@ public class AnimatedCardsView: UIView {
38
34
}
39
35
}
40
36
37
+ // MARK: Private properties
38
+ private var cardArray : [ UIView ] ! = [ ]
39
+ private lazy var gestureRecognizer : UIPanGestureRecognizer = {
40
+ return UIPanGestureRecognizer ( target: self , action: " scrollOnView: " )
41
+ } ( )
42
+
41
43
private struct PrivateConstants {
42
44
static let maxVisibleCardCount = 8
43
45
static let cardCount = 8
44
46
}
45
47
46
- var frontCardTag = 1
47
- var cardCount = PrivateConstants . cardCount
48
- var maxVisibleCardCount = PrivateConstants . maxVisibleCardCount
49
- let gradientBackgroundLayer = CAGradientLayer ( )
50
- var gestureDirection : panScrollDirection = . Up
48
+
49
+ private var cardCount = PrivateConstants . cardCount
50
+ private var maxVisibleCardCount = PrivateConstants . maxVisibleCardCount
51
+ private var gestureDirection : panScrollDirection = . Up
51
52
52
53
private var currentIndex = 0
53
54
@@ -215,7 +216,7 @@ extension AnimatedCardsView {
215
216
// MARK: Handle Layout
216
217
extension AnimatedCardsView {
217
218
218
- func relayoutSubView( subView: UIView , relativeIndex: Int , animated: Bool = true , delay: NSTimeInterval = 0 , haveBorderWidth: Bool = true , fadeAndDelete delete: Bool = false ) {
219
+ private func relayoutSubView( subView: UIView , relativeIndex: Int , animated: Bool = true , delay: NSTimeInterval = 0 , haveBorderWidth: Bool = true , fadeAndDelete delete: Bool = false ) {
219
220
let width = Constants . DefaultSize. width
220
221
subView. layer. anchorPoint = CGPointMake ( 0.5 , 1 )
221
222
@@ -259,7 +260,7 @@ extension AnimatedCardsView {
259
260
} )
260
261
}
261
262
262
- func relayoutSubViewsAnimated( animated: Bool , removeLast remove: Bool = false ) {
263
+ private func relayoutSubViewsAnimated( animated: Bool , removeLast remove: Bool = false ) {
263
264
for (index, view) in cardArray. enumerate ( ) {
264
265
let shouldDelete = remove && index == cardArray. count- 1
265
266
let delay = animated ? 0.1 * Double( index) : 0
@@ -270,28 +271,28 @@ extension AnimatedCardsView {
270
271
}
271
272
}
272
273
273
- //MARK: Helper Method
274
+ //MARK: Helper Methods
274
275
//f(x) = k * x + m
275
- func calculateFactorOfFunction( x1: CGFloat , x2: CGFloat , y1: CGFloat , y2: CGFloat ) -> ( CGFloat , CGFloat ) {
276
+ private func calculateFactorOfFunction( x1: CGFloat , x2: CGFloat , y1: CGFloat , y2: CGFloat ) -> ( CGFloat , CGFloat ) {
276
277
277
278
let k = ( y1- y2) / ( x1- x2)
278
279
let m = ( x1*y2 - x2*y1) / ( x1- x2)
279
280
280
281
return ( k, m)
281
282
}
282
283
283
- func calculateResult( argument x: Int , k: CGFloat , m: CGFloat ) -> CGFloat {
284
+ private func calculateResult( argument x: Int , k: CGFloat , m: CGFloat ) -> CGFloat {
284
285
return k * CGFloat( x) + m
285
286
}
286
287
287
- func calcuteResultWith( x1: CGFloat , x2: CGFloat , y1: CGFloat , y2: CGFloat , argument: Int ) -> CGFloat {
288
+ private func calcuteResultWith( x1: CGFloat , x2: CGFloat , y1: CGFloat , y2: CGFloat , argument: Int ) -> CGFloat {
288
289
let ( k, m) = calculateFactorOfFunction ( x1, x2: x2, y1: y1, y2: y2)
289
290
return calculateResult ( argument: argument, k: k, m: m)
290
291
}
291
292
292
293
//I set the gap between 0Card and 1st Card is 35, gap between the last two card is 15. These value on iPhone is a little big, you could make it less.
293
294
//设定头两个卡片的距离为35,最后两张卡片之间的举例为15。不设定成等距才符合视觉效果。
294
- func calculusYOffsetForIndex( indexInQueue: Int ) -> CGFloat {
295
+ private func calculusYOffsetForIndex( indexInQueue: Int ) -> CGFloat {
295
296
if indexInQueue < 1 {
296
297
return CGFloat ( 0 )
297
298
}
@@ -308,7 +309,7 @@ extension AnimatedCardsView {
308
309
return sum
309
310
}
310
311
311
- func calculateWidthScaleForIndex( indexInQueue: Int ) -> CGFloat {
312
+ private func calculateWidthScaleForIndex( indexInQueue: Int ) -> CGFloat {
312
313
let widthBaseScale : CGFloat = 0.5
313
314
314
315
var factor : CGFloat = 1
@@ -323,7 +324,7 @@ extension AnimatedCardsView {
323
324
324
325
//Zoom out card one by one.
325
326
//为符合视觉以及营造景深效果,卡片依次缩小
326
- func calculateScaleFactorForIndex( indexInQueue: Int ) -> CGFloat {
327
+ private func calculateScaleFactorForIndex( indexInQueue: Int ) -> CGFloat {
327
328
if indexInQueue < 1 {
328
329
return CGFloat ( 1 )
329
330
}
@@ -336,7 +337,7 @@ extension AnimatedCardsView {
336
337
return scale
337
338
}
338
339
339
- func calculateAlphaForIndex( indexInQueue: Int ) -> CGFloat {
340
+ private func calculateAlphaForIndex( indexInQueue: Int ) -> CGFloat {
340
341
if indexInQueue < 1 {
341
342
return CGFloat ( 1 )
342
343
}
@@ -351,7 +352,7 @@ extension AnimatedCardsView {
351
352
return alpha
352
353
}
353
354
354
- func calculateBorderWidthForIndex( indexInQueue: Int , initialBorderWidth: CGFloat ) -> CGFloat {
355
+ private func calculateBorderWidthForIndex( indexInQueue: Int , initialBorderWidth: CGFloat ) -> CGFloat {
355
356
let scaleFactor = calculateScaleFactorForIndex ( indexInQueue)
356
357
return scaleFactor * initialBorderWidth
357
358
}
0 commit comments