|
1 | 1 | # CardAnimation
|
2 |
| -[Design from Dribble](https://dribbble.com/shots/1265487-First-shot-in-Chapps-Animation),[blog](http://www.jianshu.com/p/286222d4edf8) for this, only chinese. |
| 2 | +[Design from Dribble](https://dribbble.com/shots/1265487-First-shot-in-Chapps-Animation). And a [blog](http://www.jianshu.com/p/286222d4edf8) for this, only chinese. |
3 | 3 | 
|
4 | 4 |
|
| 5 | +Thanks for [@luxorules](https://github.com/luxorules/CardAnimation/tree/Component)'s great work. Now you can use this animation in your project easily. |
| 6 | + |
| 7 | +Features: |
| 8 | +- Custom card View size. (New added by @luxorules) |
| 9 | +- Custom card view, not only image view. (New added by @luxorules) |
| 10 | +- Support pan gesture. |
| 11 | + |
| 12 | +**How to use it in your project** |
| 13 | + |
| 14 | +Drap class files in the "Classes" folder into your project, includes CardAnimationView.swift and ImageCardView.swift. |
| 15 | + |
| 16 | +Classes: |
| 17 | + |
| 18 | +- CardAnimationView: UIView, the view to display a list of card view. |
| 19 | +- BasedCardView: UIView, all custom card view must be inherited from this class. |
| 20 | +- ImageCardView: BasedCardView, child class of BasedCardView, if you just want to use image, use this class. |
| 21 | + |
| 22 | +You can custom animation behavior by set the below properties. |
| 23 | + |
| 24 | +/// Animation time for a single card animation. |
| 25 | + |
| 26 | +`public var animationsSpeed = 0.2` |
| 27 | + |
| 28 | +// Defines the card size that will be used. (width, height) |
| 29 | + |
| 30 | +`public var cardSize : (width:CGFloat, height:CGFloat)` |
| 31 | + |
| 32 | +CardAnimationView needs a data source delegate to display the content, like UICollectionView. |
| 33 | + |
| 34 | +`public weak var dataSourceDelegate : CardAnimationViewDataSource?` |
| 35 | + |
| 36 | + protocol CardAnimationViewDataSource : class { |
| 37 | + func numberOfVisibleCards() -> Int |
| 38 | + func numberOfCards() -> Int |
| 39 | + /** |
| 40 | + Ask the delegate for a new card to display in the container. |
| 41 | + - parameter number: number that is needed to be displayed. |
| 42 | + - parameter reusedView: the component may provide you with an unused view. |
| 43 | + - returns: correctly configured card view. |
| 44 | + */ |
| 45 | + func cardNumber(number:Int, reusedView:BaseCardView?) -> BaseCardView |
| 46 | + } |
| 47 | + |
| 48 | +How to reuse a card view? There is an example in `ComponentExampleViewController.swift`: |
| 49 | + |
| 50 | + func cardNumber(number: Int, reusedView: BaseCardView?) -> BaseCardView { |
| 51 | + var retView : ImageCardView? = reusedView as? ImageCardView |
| 52 | + print(" 🃏 Requested card number \(number)") |
| 53 | + if retView == nil { |
| 54 | + retView = ImageCardView(frame: CGRect(x: 0, y: 0, width: 10, height: 10)) |
| 55 | + } else { |
| 56 | + print(" ✌️ View Cached ✌️ ") |
| 57 | + } |
| 58 | + retView!.imageView.image = UIImage.init(named: JusticeLeagueLogos.logoArray[number].rawValue) |
| 59 | + return retView! |
| 60 | + } |
| 61 | + |
| 62 | +**Techniques in the animation:** |
5 | 63 |
|
6 | 64 | **Change Anchor Point of CALayer**
|
7 | 65 |
|
@@ -51,7 +109,7 @@ You could use 'CGFloat(-M_PI) * 0.99' to fix this.
|
51 | 109 |
|
52 | 110 | **To-Do List**
|
53 | 111 |
|
54 |
| -1. reuse card view |
| 112 | +~~1. reuse card view~~ |
55 | 113 |
|
56 | 114 | 2. reorder card view
|
57 | 115 |
|
|
0 commit comments