feat:add iOS AnimationSet
This commit is contained in:
parent
9c2348a19c
commit
d24b8a1789
@ -173,19 +173,19 @@ class AnimatorDemo extends Panel {
|
|||||||
translate.toTranslationX = 200
|
translate.toTranslationX = 200
|
||||||
translate.fromTranslationY = 10
|
translate.fromTranslationY = 10
|
||||||
translate.toTranslationY = 200
|
translate.toTranslationY = 200
|
||||||
translate.duration = 1000
|
translate.duration = 3000
|
||||||
|
|
||||||
const scale = new ScaleAnimation
|
const scale = new ScaleAnimation
|
||||||
scale.fromScaleX = 1
|
scale.fromScaleX = 1
|
||||||
scale.toScaleX = 5
|
scale.toScaleX = 5
|
||||||
scale.fromScaleY = 1
|
scale.fromScaleY = 1
|
||||||
scale.toScaleY = 5
|
scale.toScaleY = 5
|
||||||
scale.duration = 1000
|
scale.duration = 3000
|
||||||
|
|
||||||
const rotation = new RotationAnimation
|
const rotation = new RotationAnimation
|
||||||
rotation.fromRotation = 0
|
rotation.fromRotation = 0
|
||||||
rotation.toRotation = 6
|
rotation.toRotation = 6
|
||||||
rotation.duration = 1000
|
rotation.duration = 3000
|
||||||
|
|
||||||
animationSet.addAnimation(translate)
|
animationSet.addAnimation(translate)
|
||||||
animationSet.addAnimation(scale)
|
animationSet.addAnimation(scale)
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#import "DoricConstant.h"
|
#import "DoricConstant.h"
|
||||||
#import "DoricSuperNode.h"
|
#import "DoricSuperNode.h"
|
||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
|
#import "DoricPromise.h"
|
||||||
|
|
||||||
void DoricAddEllipticArcPath(CGMutablePathRef path,
|
void DoricAddEllipticArcPath(CGMutablePathRef path,
|
||||||
CGPoint origin,
|
CGPoint origin,
|
||||||
@ -309,4 +310,95 @@ - (void)blendLayoutConfig:(NSDictionary *)params {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)doAnimation:(id)params withPromise:(DoricPromise *)promise {
|
||||||
|
CAAnimation *animation = [self parseAnimation:params];
|
||||||
|
animation.removedOnCompletion = NO;
|
||||||
|
animation.fillMode = kCAFillModeForwards;
|
||||||
|
[self.view.layer addAnimation:animation forKey:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CAAnimation *)parseAnimation:(id)params {
|
||||||
|
if ([params isKindOfClass:[NSArray class]]) {
|
||||||
|
NSArray *anims = params;
|
||||||
|
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
|
||||||
|
NSMutableArray *animations = [NSMutableArray new];
|
||||||
|
[anims forEach:^(id obj) {
|
||||||
|
[animations addObject:[self parseAnimation:obj]];
|
||||||
|
}];
|
||||||
|
animationGroup.animations = animations;
|
||||||
|
return animationGroup;
|
||||||
|
} else if ([params isKindOfClass:[NSDictionary class]]) {
|
||||||
|
NSArray<NSDictionary *> *changeables = params[@"changeables"];
|
||||||
|
NSString *type = params[@"type"];
|
||||||
|
if ([@"TranslationAnimation" isEqualToString:type]) {
|
||||||
|
__block CGPoint from = self.view.layer.position;
|
||||||
|
__block CGPoint to = self.view.layer.position;
|
||||||
|
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
|
||||||
|
[changeables forEach:^(NSDictionary *obj) {
|
||||||
|
NSString *key = obj[@"key"];
|
||||||
|
if ([@"translationX" isEqualToString:key]) {
|
||||||
|
from.x += [obj[@"fromValue"] floatValue];
|
||||||
|
to.x += [obj[@"toValue"] floatValue];
|
||||||
|
} else if ([@"translationY" isEqualToString:key]) {
|
||||||
|
from.y += [obj[@"fromValue"] floatValue];
|
||||||
|
to.y += [obj[@"toValue"] floatValue];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
animation.fromValue = [NSValue valueWithCGPoint:from];
|
||||||
|
animation.toValue = [NSValue valueWithCGPoint:to];
|
||||||
|
return animation;
|
||||||
|
} else {
|
||||||
|
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
|
||||||
|
NSMutableArray *animations = [NSMutableArray new];
|
||||||
|
[changeables forEach:^(NSDictionary *obj) {
|
||||||
|
[animations addObject:[self parseChangeable:obj]];
|
||||||
|
}];
|
||||||
|
animationGroup.animations = animations;
|
||||||
|
animationGroup.duration = [params[@"duration"] floatValue] / 1000;
|
||||||
|
if (params[@"delay"]) {
|
||||||
|
animationGroup.beginTime = CACurrentMediaTime() + [params[@"delay"] floatValue] / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
return animationGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CAAnimation *)parseChangeable:(NSDictionary *)params {
|
||||||
|
NSString *key = params[@"key"];
|
||||||
|
CABasicAnimation *animation = [CABasicAnimation animation];
|
||||||
|
if ([@"scaleX" isEqualToString:key]) {
|
||||||
|
animation.keyPath = @"transform.scale.x";
|
||||||
|
animation.fromValue = params[@"fromValue"];
|
||||||
|
animation.toValue = params[@"toValue"];
|
||||||
|
} else if ([@"scaleY" isEqualToString:key]) {
|
||||||
|
animation.keyPath = @"transform.scale.y";
|
||||||
|
animation.fromValue = params[@"fromValue"];
|
||||||
|
animation.toValue = params[@"toValue"];
|
||||||
|
} else if ([@"rotation" isEqualToString:key]) {
|
||||||
|
animation.keyPath = @"transform.rotation.z";
|
||||||
|
animation.fromValue = @([params[@"fromValue"] floatValue] * M_PI);
|
||||||
|
animation.toValue = @([params[@"toValue"] floatValue] * M_PI);
|
||||||
|
} else if ([@"bgColor" isEqualToString:key]) {
|
||||||
|
animation.keyPath = @"backgroundColor";
|
||||||
|
animation.fromValue = params[@"fromValue"];
|
||||||
|
animation.toValue = params[@"toValue"];
|
||||||
|
}
|
||||||
|
if (params[@"repeatCount"]) {
|
||||||
|
NSInteger repeatCount = [params[@"repeatCount"] integerValue];
|
||||||
|
if (repeatCount < 0) {
|
||||||
|
repeatCount = NSNotFound;
|
||||||
|
}
|
||||||
|
animation.repeatCount = repeatCount;
|
||||||
|
}
|
||||||
|
if (params[@"repeatMode"]) {
|
||||||
|
NSInteger repeatMode = [params[@"repeatMode"] integerValue];
|
||||||
|
animation.autoreverses = repeatMode == 2;
|
||||||
|
}
|
||||||
|
return animation;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user