forked from svga/SVGAPlayer-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
129 lines (106 loc) · 5.13 KB
/
ViewController.m
File metadata and controls
129 lines (106 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// ViewController.m
// SVGAPlayer
//
// Created by 崔明辉 on 16/6/17.
// Copyright © 2016年 UED Center. All rights reserved.
//
#import "ViewController.h"
#import "SVGA.h"
@interface ViewController ()<SVGAPlayerDelegate>
@property (weak, nonatomic) IBOutlet SVGAPlayer *aPlayer;
@property (weak, nonatomic) IBOutlet UISlider *aSlider;
@property (weak, nonatomic) IBOutlet UIButton *onBeginButton;
@end
@implementation ViewController
static SVGAParser *parser;
- (void)viewDidLoad {
[super viewDidLoad];
self.aPlayer.delegate = self;
self.aPlayer.loops = 1;
self.aPlayer.clearsAfterStop = YES;
parser = [[SVGAParser alloc] init];
[self onChange:nil];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self onBeginButton:self.onBeginButton];
}
- (IBAction)onChange:(id)sender {
NSArray *items = @[
@"https://github.com/yyued/SVGA-Samples/blob/master/EmptyState.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/HamburgerArrow.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/PinJump.svga?raw=true",
@"https://github.com/svga/SVGA-Samples/raw/master/Rocket.svga",
@"https://github.com/yyued/SVGA-Samples/blob/master/TwitterHeart.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/Walkthrough.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/angel.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/halloween.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/kingset.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/posche.svga?raw=true",
@"https://github.com/yyued/SVGA-Samples/blob/master/rose.svga?raw=true",
];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// parser.enabledMemoryCache = YES;
[parser parseWithURL:[NSURL URLWithString:items[arc4random() % items.count]]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
if (videoItem != nil) {
self.aPlayer.videoItem = videoItem;
NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init];
[para setLineBreakMode:NSLineBreakByTruncatingTail];
[para setAlignment:NSTextAlignmentCenter];
NSAttributedString *str = [[NSAttributedString alloc]
initWithString:@"Hello, World! Hello, World!"
attributes:@{
NSFontAttributeName: [UIFont systemFontOfSize:28],
NSForegroundColorAttributeName: [UIColor whiteColor],
NSParagraphStyleAttributeName: para,
}];
[self.aPlayer setAttributedText:str forKey:@"banner"];
[self.aPlayer startAnimation];
// [self.aPlayer startAnimationWithRange:NSMakeRange(10, 25) reverse:YES];
}
} failureBlock:nil];
//
// [parser parseWithURL:[NSURL URLWithString:@"https://github.com/svga/SVGA-Samples/raw/master_aep/BitmapColorArea1.svga"] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
// if (videoItem != nil) {
// self.aPlayer.videoItem = videoItem;
// [self.aPlayer setImageWithURL:[NSURL URLWithString: @"https://i.imgur.com/vd4GuUh.png"] forKey:@"matte_EEKdlEml.matte"];
// [self.aPlayer startAnimation];
// }
// } failureBlock:nil];
// [parser parseWithNamed:@"Rocket" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
// self.aPlayer.videoItem = videoItem;
// [self.aPlayer startAnimation];
// } failureBlock:nil];
}
- (IBAction)onSliderClick:(UISlider *)sender {
[self.aPlayer stepToPercentage:sender.value andPlay:NO];
}
- (IBAction)onSlide:(UISlider *)sender {
[self.aPlayer stepToPercentage:sender.value andPlay:NO];
}
- (IBAction)onChangeColor:(UIButton *)sender {
self.view.backgroundColor = sender.backgroundColor;
}
- (IBAction)onBeginButton:(UIButton *)sender {
sender.selected = !sender.isSelected;
if (sender.selected) {
[self.aPlayer pauseAnimation];
} else {
[self.aPlayer stepToPercentage:(self.aSlider.value == 1 ? 0 : self.aSlider.value) andPlay:YES];
}
}
- (IBAction)onRetreatButton:(UIButton *)sender {
}
- (IBAction)onForwardButton:(UIButton *)sender {
}
#pragma - mark SVGAPlayer Delegate
- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage {
self.aSlider.value = percentage;
}
- (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player {
self.onBeginButton.selected = YES;
}
@end