Skip to content

Commit 5807a23

Browse files
committed
Change visibility of functions and properties. Clean up not needed stuff.
1 parent 465bd45 commit 5807a23

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

CardAnimation/AnimatedCardView/AnimatedCardsView.swift

+22-21
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ public protocol AnimatedCardsViewDataSource : class {
1616

1717
public class AnimatedCardsView: UIView {
1818

19-
private var cardArray : [UIView]! = []
20-
private lazy var gestureRecognizer : UIPanGestureRecognizer = {
21-
return UIPanGestureRecognizer(target: self, action: "scrollOnView:")
22-
}()
23-
19+
// MARK: Public properties
2420
public weak var dataSourceDelegate : AnimatedCardsViewDataSource? {
2521
didSet {
2622
if dataSourceDelegate != nil {
@@ -38,16 +34,21 @@ public class AnimatedCardsView: UIView {
3834
}
3935
}
4036

37+
// MARK: Private properties
38+
private var cardArray : [UIView]! = []
39+
private lazy var gestureRecognizer : UIPanGestureRecognizer = {
40+
return UIPanGestureRecognizer(target: self, action: "scrollOnView:")
41+
}()
42+
4143
private struct PrivateConstants {
4244
static let maxVisibleCardCount = 8
4345
static let cardCount = 8
4446
}
4547

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
5152

5253
private var currentIndex = 0
5354

@@ -215,7 +216,7 @@ extension AnimatedCardsView {
215216
// MARK: Handle Layout
216217
extension AnimatedCardsView {
217218

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) {
219220
let width = Constants.DefaultSize.width
220221
subView.layer.anchorPoint = CGPointMake(0.5, 1)
221222

@@ -259,7 +260,7 @@ extension AnimatedCardsView {
259260
})
260261
}
261262

262-
func relayoutSubViewsAnimated(animated:Bool, removeLast remove:Bool = false){
263+
private func relayoutSubViewsAnimated(animated:Bool, removeLast remove:Bool = false){
263264
for (index, view) in cardArray.enumerate() {
264265
let shouldDelete = remove && index == cardArray.count-1
265266
let delay = animated ? 0.1 * Double(index) : 0
@@ -270,28 +271,28 @@ extension AnimatedCardsView {
270271
}
271272
}
272273

273-
//MARK: Helper Method
274+
//MARK: Helper Methods
274275
//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){
276277

277278
let k = (y1-y2)/(x1-x2)
278279
let m = (x1*y2 - x2*y1)/(x1-x2)
279280

280281
return (k, m)
281282
}
282283

283-
func calculateResult(argument x: Int, k: CGFloat, m: CGFloat) -> CGFloat{
284+
private func calculateResult(argument x: Int, k: CGFloat, m: CGFloat) -> CGFloat{
284285
return k * CGFloat(x) + m
285286
}
286287

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{
288289
let (k, m) = calculateFactorOfFunction(x1, x2: x2, y1: y1, y2: y2)
289290
return calculateResult(argument: argument, k: k, m: m)
290291
}
291292

292293
//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.
293294
//设定头两个卡片的距离为35,最后两张卡片之间的举例为15。不设定成等距才符合视觉效果。
294-
func calculusYOffsetForIndex(indexInQueue: Int) -> CGFloat{
295+
private func calculusYOffsetForIndex(indexInQueue: Int) -> CGFloat{
295296
if indexInQueue < 1{
296297
return CGFloat(0)
297298
}
@@ -308,7 +309,7 @@ extension AnimatedCardsView {
308309
return sum
309310
}
310311

311-
func calculateWidthScaleForIndex(indexInQueue: Int) -> CGFloat{
312+
private func calculateWidthScaleForIndex(indexInQueue: Int) -> CGFloat{
312313
let widthBaseScale:CGFloat = 0.5
313314

314315
var factor: CGFloat = 1
@@ -323,7 +324,7 @@ extension AnimatedCardsView {
323324

324325
//Zoom out card one by one.
325326
//为符合视觉以及营造景深效果,卡片依次缩小
326-
func calculateScaleFactorForIndex(indexInQueue: Int) -> CGFloat{
327+
private func calculateScaleFactorForIndex(indexInQueue: Int) -> CGFloat{
327328
if indexInQueue < 1{
328329
return CGFloat(1)
329330
}
@@ -336,7 +337,7 @@ extension AnimatedCardsView {
336337
return scale
337338
}
338339

339-
func calculateAlphaForIndex(indexInQueue: Int) -> CGFloat{
340+
private func calculateAlphaForIndex(indexInQueue: Int) -> CGFloat{
340341
if indexInQueue < 1{
341342
return CGFloat(1)
342343
}
@@ -351,7 +352,7 @@ extension AnimatedCardsView {
351352
return alpha
352353
}
353354

354-
func calculateBorderWidthForIndex(indexInQueue: Int, initialBorderWidth: CGFloat) -> CGFloat{
355+
private func calculateBorderWidthForIndex(indexInQueue: Int, initialBorderWidth: CGFloat) -> CGFloat{
355356
let scaleFactor = calculateScaleFactorForIndex(indexInQueue)
356357
return scaleFactor * initialBorderWidth
357358
}

0 commit comments

Comments
 (0)