mirror of
https://github.com/svga/SVGAPlayer-iOS.git
synced 2025-10-21 07:29:14 +08:00
add startAnimationWithRange method.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "SVGAPlayer"
|
||||
s.version = "2.0.1"
|
||||
s.version = "2.1.0-Beta"
|
||||
s.summary = "SVGAPlayer 是一个高性能的动画播放器"
|
||||
s.description = <<-DESC
|
||||
SVGA 是一个私有的动画格式,由 YY UED 主导开发。
|
||||
|
@@ -28,6 +28,7 @@
|
||||
@property (nonatomic, copy) NSString *fillMode;
|
||||
|
||||
- (void)startAnimation;
|
||||
- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse;
|
||||
- (void)pauseAnimation;
|
||||
- (void)stopAnimation;
|
||||
- (void)clear;
|
||||
|
@@ -14,15 +14,16 @@
|
||||
#import "SVGABitmapLayer.h"
|
||||
#import "SVGAVectorLayer.h"
|
||||
|
||||
@interface SVGAPlayer () {
|
||||
int _loopCount;
|
||||
}
|
||||
@interface SVGAPlayer ()
|
||||
|
||||
@property (nonatomic, strong) CALayer *drawLayer;
|
||||
@property (nonatomic, strong) CADisplayLink *displayLink;
|
||||
@property (nonatomic, assign) NSInteger currentFrame;
|
||||
@property (nonatomic, copy) NSDictionary *dynamicObjects;
|
||||
@property (nonatomic, copy) NSDictionary *dynamicTexts;
|
||||
@property (nonatomic, assign) int loopCount;
|
||||
@property (nonatomic, assign) NSRange currentRange;
|
||||
@property (nonatomic, assign) BOOL reversing;
|
||||
|
||||
@end
|
||||
|
||||
@@ -46,12 +47,24 @@
|
||||
|
||||
- (void)startAnimation {
|
||||
[self stopAnimation:NO];
|
||||
_loopCount = 0;
|
||||
self.loopCount = 0;
|
||||
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(next)];
|
||||
self.displayLink.frameInterval = 60 / self.videoItem.FPS;
|
||||
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
||||
}
|
||||
|
||||
- (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse {
|
||||
self.currentRange = range;
|
||||
self.reversing = reverse;
|
||||
if (reverse) {
|
||||
self.currentFrame = MIN(self.videoItem.frames - 1, range.location + range.length - 1);
|
||||
}
|
||||
else {
|
||||
self.currentFrame = MAX(0, range.location);
|
||||
}
|
||||
[self startAnimation];
|
||||
}
|
||||
|
||||
- (void)pauseAnimation {
|
||||
[self stopAnimation:NO];
|
||||
}
|
||||
@@ -128,7 +141,6 @@
|
||||
}
|
||||
}];
|
||||
[self.layer addSublayer:self.drawLayer];
|
||||
self.currentFrame = 0;
|
||||
[self update];
|
||||
[self resize];
|
||||
}
|
||||
@@ -222,22 +234,34 @@
|
||||
}
|
||||
|
||||
- (void)next {
|
||||
self.currentFrame++;
|
||||
if (self.currentFrame >= self.videoItem.frames) {
|
||||
self.currentFrame = 0;
|
||||
_loopCount++;
|
||||
if (self.loops > 0 && _loopCount >= self.loops) {
|
||||
[self stopAnimation];
|
||||
if (!self.clearsAfterStop && [self.fillMode isEqualToString:@"Backward"]) {
|
||||
[self stepToFrame:0 andPlay:NO];
|
||||
}
|
||||
id delegate = self.delegate;
|
||||
if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidFinishedAnimation:)]) {
|
||||
[delegate svgaPlayerDidFinishedAnimation:self];
|
||||
}
|
||||
return;
|
||||
if (self.reversing) {
|
||||
self.currentFrame--;
|
||||
if (self.currentFrame < (NSInteger)MAX(0, self.currentRange.location)) {
|
||||
self.currentFrame = MIN(self.videoItem.frames - 1, self.currentRange.location + self.currentRange.length - 1);
|
||||
self.loopCount++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.currentFrame++;
|
||||
if (self.currentFrame >= MIN(self.videoItem.frames, self.currentRange.location + self.currentRange.length)) {
|
||||
self.currentFrame = MAX(0, self.currentRange.location);
|
||||
self.loopCount++;
|
||||
}
|
||||
}
|
||||
if (self.loops > 0 && self.loopCount >= self.loops) {
|
||||
[self stopAnimation];
|
||||
if (!self.clearsAfterStop && [self.fillMode isEqualToString:@"Backward"]) {
|
||||
[self stepToFrame:MAX(0, self.currentRange.location) andPlay:NO];
|
||||
}
|
||||
else if (!self.clearsAfterStop && [self.fillMode isEqualToString:@"Forward"]) {
|
||||
[self stepToFrame:MIN(self.videoItem.frames - 1, self.currentRange.location + self.currentRange.length - 1) andPlay:NO];
|
||||
}
|
||||
id delegate = self.delegate;
|
||||
if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidFinishedAnimation:)]) {
|
||||
[delegate svgaPlayerDidFinishedAnimation:self];
|
||||
}
|
||||
return;
|
||||
}
|
||||
[self update];
|
||||
id delegate = self.delegate;
|
||||
if (delegate != nil && [delegate respondsToSelector:@selector(svgaPlayerDidAnimatedToFrame:)]) {
|
||||
@@ -250,6 +274,9 @@
|
||||
|
||||
- (void)setVideoItem:(SVGAVideoEntity *)videoItem {
|
||||
_videoItem = videoItem;
|
||||
_currentRange = NSMakeRange(0, videoItem.frames);
|
||||
_reversing = NO;
|
||||
_currentFrame = 0;
|
||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
||||
[self clear];
|
||||
[self draw];
|
||||
|
@@ -86,6 +86,7 @@ Deliver NSData to SVGAParser, as usual.
|
||||
### Methods
|
||||
|
||||
* (void)startAnimation; - Play Animation from 0 frame.
|
||||
* (void)startAnimationWithRange:(NSRange)range reverse:(BOOL)reverse;
|
||||
* (void)pauseAnimation; - Pause Animation and keep on current frame.
|
||||
* (void)stopAnimation; - Stop Animation,Clears Canvas while clearsAfterStop == YES.
|
||||
* (void)clear; - Clear Canvas force.
|
||||
|
Reference in New Issue
Block a user