Skip to content

Commit 01914ec

Browse files
committed
doc: update readme.
1 parent 116a91f commit 01914ec

File tree

2 files changed

+137
-111
lines changed

2 files changed

+137
-111
lines changed

readme.md

Lines changed: 52 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,91 @@
11
# SVGAPlayer
22

3-
## 咨询服务
3+
[简体中文](./readme.zh.md)
44

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.
76

8-
#### New Features
7+
`SVGAPlayer-iOS` render animation natively via iOS CoreAnimation Framework, brings you a high-performance, low-cost animation experience.
98

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/).
1310

14-
#### Improvements
11+
## Usage
1512

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).
1814

19-
## SVGA Format
15+
### Install Via CocoaPods
2016

21-
@see https://github.com/yyued/SVGA-Format
17+
You want to add pod 'SVGAPlayer', '~> 2.3' similar to the following to your Podfile:
2218

23-
## Install
19+
target 'MyApp' do
20+
pod 'SVGAPlayer', '~> 2.3'
21+
end
2422

25-
### CocoaPods
23+
Then run a `pod install` inside your terminal, or from CocoaPods.app.
2624

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.
3036
```
3137
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+
```
3345

34-
### code
46+
#### Create a `SVGAParser` instance, parse from remote server like this.
3547

3648
```objectivec
3749
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) {
4159
if (videoItem != nil) {
4260
player.videoItem = videoItem;
4361
[player startAnimation];
4462
}
4563
} failureBlock:nil];
46-
4764
```
4865

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
5567

56-
## Cache
68+
`SVGAParser` use `NSURLSession` request remote data via network. You may use following ways to control cache.
5769

58-
SVGAParser use NSURLSession request remote data via network. You may use following ways to control cache.
59-
60-
### Response Header
70+
#### Response Header
6171

6272
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.
6373

64-
### Request NSData By Yourself
74+
#### Request NSData By Yourself
6575

6676
If you couldn't fix Server Response Header, You should build NSURLRequest with CachePolicy by yourself, and fetch NSData.
6777

6878
Deliver NSData to SVGAParser, as usual.
6979

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
7881

79-
### Methods
82+
Here are many feature samples.
8083

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)
9288

93-
### SVGAPlayerDelegate
89+
## APIs
9490

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)

readme.zh.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# SVGAPlayer
2+
3+
`SVGAPlayer` 是一个轻量的动画渲染库。你可以使用[工具](http://svga.io/designer.html)`Adobe Animate CC` 或者 `Adobe After Effects` 中导出动画文件,然后使用 `SVGAPlayer` 在移动设备上渲染并播放。
4+
5+
`SVGAPlayer-iOS` 使用原生 CoreAnimation 库渲染动画,为你提供高性能、低开销的动画体验。
6+
7+
如果你想要了解更多细节,请访问[官方网站](http://svga.io/)
8+
9+
## 用法
10+
11+
我们在这里介绍 `SVGAPlayer-iOS` 的用法。想要知道如何导出动画,点击[这里](http://svga.io/designer.html)
12+
13+
### 使用 CocoaPods 安装依赖
14+
15+
添加依赖 'SVGAPlayer', '~> 2.3' 到 Podfile 文件中:
16+
17+
target 'MyApp' do
18+
pod 'SVGAPlayer', '~> 2.3'
19+
end
20+
21+
然后在终端执行 `pod install`
22+
23+
### 放置 svga 文件
24+
25+
SVGAPlayer 可以从应用包,或者远端服务器上加载动画文件。
26+
27+
### 代码
28+
29+
#### 创建一个 `SVGAPlayer` 实例
30+
31+
```objectivec
32+
SVGAPlayer *player = [[SVGAPlayer alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
33+
[self.view addSubview:player]; // Add subview by yourself.
34+
```
35+
36+
#### 创建一个 `SVGAParser` 实例,使用以下方法从应用包中加载动画。
37+
```objectivec
38+
SVGAParser *parser = [[SVGAParser alloc] init];
39+
[parser parseWithNamed:@"posche" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
40+
41+
} failureBlock:nil];
42+
```
43+
44+
#### 创建一个 `SVGAParser` 实例,使用以下方法从远端服务器中加载动画。
45+
46+
```objectivec
47+
SVGAParser *parser = [[SVGAParser alloc] init];
48+
[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
49+
50+
} failureBlock:nil];
51+
```
52+
53+
#### 将 videoItem 赋值给 `SVGAPlayer`,然后播放动画。
54+
55+
```objectivec
56+
[parser parseWithURL:[NSURL URLWithString:@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
57+
if (videoItem != nil) {
58+
player.videoItem = videoItem;
59+
[player startAnimation];
60+
}
61+
} failureBlock:nil];
62+
```
63+
64+
### 缓存
65+
66+
`SVGAParser` 使用 `NSURLSession` 请求远端数据,你需要通过以下方式缓存动画文件。
67+
68+
#### HTTP 结果头部信息
69+
70+
如果服务器返回的头部信息包含 cache-control / etag / expired 这些键值,这个请求会被合理地缓存到本地。
71+
72+
#### 自行缓存 NSData
73+
74+
如果你没有办法控制服务器返回的头部信息,你可以自行获取对应的 svga 文件 `NSData` 数据,然后使用 `SVGAParser` 解析这些数据。
75+
76+
## 功能示例
77+
78+
* [使用位图替换指定元素。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Image)
79+
* [在指定元素上绘制文本。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Text)
80+
* [隐藏指定元素。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Hidden)
81+
* [在指定元素上自由绘制。](https://github.com/yyued/SVGAPlayer-iOS/wiki/Dynamic-Drawer)
82+
83+
## APIs
84+
85+
请参阅此处 [https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs](https://github.com/yyued/SVGAPlayer-iOS/wiki/APIs)

0 commit comments

Comments
 (0)