|
1 | 1 | # SVGAPlayer |
2 | 2 |
|
3 | | -## 咨询服务 |
| 3 | +[简体中文](./readme.zh.md) |
4 | 4 |
|
5 | | -* 如果你发现 SVGAPlayer 存在 BUG,请在 GitHub 上按照模板提交 issue。 |
6 | | -* 如果有使用上的问题,请勿提交 issue(会被立刻关闭),请至[知乎付费问答](https://www.zhihu.com/zhi/people/1011556735563157504)提问,我们会全程跟踪你的疑问。 |
| 5 | +SVGAPlayer is a light-weight animation renderer. You use [tools](http://svga.io/designer.html) to export `svga` file from `Adobe Animate CC` or `Adobe After Effects`, and then use SVGAPlayer to render animation on mobile application. |
7 | 6 |
|
8 | | -#### New Features |
| 7 | +`SVGAPlayer-iOS` render animation natively via iOS CoreAnimation Framework, brings you a high-performance, low-cost animation experience. |
9 | 8 |
|
10 | | -* Add SVGA-Format 2.0.0 support. |
11 | | -* Add SVGAImageView. |
12 | | -* Add more UIViewContentMode support. |
| 9 | +If wonder more information, go to this [website](http://svga.io/). |
13 | 10 |
|
14 | | -#### Improvements |
| 11 | +## Usage |
15 | 12 |
|
16 | | -* SVGAParser now can works up-to 8 concurrent tasks. |
17 | | -* Improves BezierPath performance. |
| 13 | +Here introduce `SVGAPlayer-iOS` usage. Wonder exporting usage? Click [here](http://svga.io/designer.html). |
18 | 14 |
|
19 | | -## SVGA Format |
| 15 | +### Install Via CocoaPods |
20 | 16 |
|
21 | | -@see https://github.com/yyued/SVGA-Format |
| 17 | +You want to add pod 'SVGAPlayer', '~> 2.3' similar to the following to your Podfile: |
22 | 18 |
|
23 | | -## Install |
| 19 | +target 'MyApp' do |
| 20 | + pod 'SVGAPlayer', '~> 2.3' |
| 21 | +end |
24 | 22 |
|
25 | | -### CocoaPods |
| 23 | +Then run a `pod install` inside your terminal, or from CocoaPods.app. |
26 | 24 |
|
27 | | -Add following dependency to Podfile |
28 | | -``` |
29 | | -pod 'SVGAPlayer' |
| 25 | +### Locate files |
| 26 | + |
| 27 | +SVGAPlayer could load svga file from application bundle or remote server. |
| 28 | + |
| 29 | +### Using code |
| 30 | + |
| 31 | +#### Create a `SVGAPlayer` instance. |
| 32 | + |
| 33 | +```objectivec |
| 34 | +SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; |
| 35 | +[self.view addSubview:player]; // Add subview by yourself. |
30 | 36 | ``` |
31 | 37 |
|
32 | | -## Usage |
| 38 | +#### Create a `SVGAParser` instance, parse from bundle like this. |
| 39 | +```objectivec |
| 40 | +SVGAParser *parser = [[SVGAParser alloc] init]; |
| 41 | +[parser parseWithNamed:@"posche" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) { |
| 42 | + |
| 43 | +} failureBlock:nil]; |
| 44 | +``` |
33 | 45 |
|
34 | | -### code |
| 46 | +#### Create a `SVGAParser` instance, parse from remote server like this. |
35 | 47 |
|
36 | 48 | ```objectivec |
37 | 49 | SVGAParser *parser = [[SVGAParser alloc] init]; |
38 | | -SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; |
39 | | -[self.view addSubview:player]; |
40 | | -[parser parseWithURL:[NSURL URLWithString:@"http://uedfe.yypm.com/assets/svga-samples/angel.svga"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { |
| 50 | +[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { |
| 51 | + |
| 52 | +} failureBlock:nil]; |
| 53 | +``` |
| 54 | +
|
| 55 | +#### Set videoItem to `SVGAPlayer`, play it as you want. |
| 56 | +
|
| 57 | +```objectivec |
| 58 | +[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) { |
41 | 59 | if (videoItem != nil) { |
42 | 60 | player.videoItem = videoItem; |
43 | 61 | [player startAnimation]; |
44 | 62 | } |
45 | 63 | } failureBlock:nil]; |
46 | | - |
47 | 64 | ``` |
48 | 65 |
|
49 | | -### xib |
50 | | -
|
51 | | -1. Add UIView to IB layout area. |
52 | | -2. Let UIView subclass SVGAImageView. |
53 | | -3. Input imageName on IB Properties Area. |
54 | | -4. Animation will start after loaded. |
| 66 | +### Cache |
55 | 67 |
|
56 | | -## Cache |
| 68 | +`SVGAParser` use `NSURLSession` request remote data via network. You may use following ways to control cache. |
57 | 69 |
|
58 | | -SVGAParser use NSURLSession request remote data via network. You may use following ways to control cache. |
59 | | -
|
60 | | -### Response Header |
| 70 | +#### Response Header |
61 | 71 |
|
62 | 72 | Server response SVGA files in Body, and response header either. response header has cache-control / etag / expired keys, all these keys telling NSURLSession how to handle cache. |
63 | 73 |
|
64 | | -### Request NSData By Yourself |
| 74 | +#### Request NSData By Yourself |
65 | 75 |
|
66 | 76 | If you couldn't fix Server Response Header, You should build NSURLRequest with CachePolicy by yourself, and fetch NSData. |
67 | 77 |
|
68 | 78 | Deliver NSData to SVGAParser, as usual. |
69 | 79 |
|
70 | | -## API |
71 | | -
|
72 | | -### Properties |
73 | | -* id<SVGAPlayerDelegate> delegate; - Callbacks |
74 | | -* SVGAVideoEntity *videoItem; - Animation Instance |
75 | | -* Int loops; - Loop Count,0 = Infinity Loop |
76 | | -* BOOL clearsAfterStop; - Clears Canvas After Animation Stop |
77 | | -* String fillMode; - defaults to Forward,optional Forward / Backward,fillMode = Forward,Animation will pause on last frame while finished,fillMode = Backward , Animation will pause on first frame. |
| 80 | +## Features |
78 | 81 |
|
79 | | -### Methods |
| 82 | +Here are many feature samples. |
80 | 83 |
|
81 | | -* (void)startAnimation; - Play Animation from 0 frame. |
82 | | -* (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse; |
83 | | -* (void)pauseAnimation; - Pause Animation and keep on current frame. |
84 | | -* (void)stopAnimation; - Stop Animation,Clears Canvas while clearsAfterStop == YES. |
85 | | -* (void)clear; - Clear Canvas force. |
86 | | -* (void)stepToFrame:(NSInteger)frame andPlay:(BOOL)andPlay; - Step to N frame, and then Play Animation if andPlay === true. |
87 | | -* (void)stepToPercentage:(CGFloat)percentage andPlay:(BOOL)andPlay; - Step to x%, and then Play Animation if andPlay === true. |
88 | | -* (void)setImage:(UIImage *)image forKey:(NSString *)aKey; - Set Dynamic Image. |
89 | | -* (void)setImageWithURL:(NSURL *)URL forKey:(NSString *)aKey; - Set Dynamic Image via remote URL. |
90 | | -* (void)setAttributedText:(NSAttributedString *)attributedText forKey:(NSString *)aKey; - Set Dynamic Text. |
91 | | -* (void)clearDynamicObjects; - Clear all dynamic Images and Texts. |
| 84 | +* [Replace an element with Bitmap.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Image) |
| 85 | +* [Add text above an element.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Text) |
| 86 | +* [Hides an element dynamicaly.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Hidden) |
| 87 | +* [Use a custom drawer for element.](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Drawer) |
92 | 88 |
|
93 | | -### SVGAPlayerDelegate |
| 89 | +## APIs |
94 | 90 |
|
95 | | -* @optional |
96 | | -* - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player; - Call after animation finished. |
97 | | -* - (void)svgaPlayerDidAnimatedToFrame:(NSInteger)frame; - Call after animation play to specific frame. |
98 | | -* - (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage; - Call after animation play to specific percentage. |
99 | | -
|
100 | | -### Dynamic Object |
101 | | -
|
102 | | -Use this way to replace specific image, or add text to it. (可以通过以下方式,替换动画文件中的指定图像,以及动态添加富文本。) |
103 | | -
|
104 | | -#### Dynamic Image |
105 | | -
|
106 | | -```objectivec |
107 | | -CALayer *iconLayer = [CALayer layer]; |
108 | | -iconLayer.cornerRadius = 84.0; |
109 | | -iconLayer.masksToBounds = YES; |
110 | | -iconLayer.borderWidth = 4.0; |
111 | | -iconLayer.borderColor = [UIColor colorWithRed:0xea/255.0 green:0xb3/255.0 blue:0x7d/255.0 alpha:1.0].CGColor; |
112 | | -[self.aPlayer setImage:iconImage forKey:@"99" referenceLayer:iconLayer]; |
113 | | -``` |
114 | | - |
115 | | -* Ask designer tell you the imageKey(or unzip the svga file, find it). |
116 | | - |
117 | | -#### Dynamic Text |
118 | | - |
119 | | -```objectivec |
120 | | -NSShadow *shadow = [NSShadow new]; |
121 | | -shadow.shadowColor = [UIColor blackColor]; |
122 | | -shadow.shadowOffset = CGSizeMake(0, 1); |
123 | | -NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"崔小姐不吃鱼 送了魔法奇缘" |
124 | | - attributes:@{ |
125 | | - NSForegroundColorAttributeName: [UIColor colorWithRed:0xff/255.0 green:0xe0/255.0 blue:0xa4/255.0 alpha:1.0], |
126 | | - NSFontAttributeName: [UIFont boldSystemFontOfSize:30.0], |
127 | | - NSShadowAttributeName: shadow, |
128 | | - }]; |
129 | | -[self.aPlayer setAttributedText:text forKey:@"banner"]; |
130 | | -``` |
131 | | -
|
132 | | -* Ask designer tell you the imageKey(or unzip the svga file, find it). |
133 | | -
|
134 | | -#### Dynamic Hidden |
135 | | -
|
136 | | -Now use setHidden to hide an element prevents drawing. |
137 | | -
|
138 | | -```objectivec |
139 | | -[self.aPlayer setHidden:YES forKey:@"99"]; |
140 | | -``` |
141 | | - |
142 | | -#### Dynamic Drawing |
143 | | - |
144 | | -You can set a block, it will callback while frame step. |
145 | | - |
146 | | -```objectivec |
147 | | -[self.aPlayer setDrawingBlock:^(CALayer *contentLayer, NSInteger frameIndex) { |
148 | | - // do thing by yourself |
149 | | -} forKey:@"99"]; |
150 | | -``` |
| 91 | +Head on over to [https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs](https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs) |
0 commit comments