MMTweenAnimation 是 Facebook 的 POP(Property Object)自定义动画的扩展。受 tweaner (https://code.google.com/p/tweaner) 的启发,MMTweenAnimation 在使用 POP 的同时提供 10 种自定义动画。
动画功能基于 缓动函数
缓动函数指定参数随时间变化的速率,并允许您将自定义数学公式应用于动画。
首选的安装方式是通过 CocoaPods。只需添加
pod 'MMTweenAnimation'
并运行 pod install
。它将安装 MMTweenAnimation 的最新版本。
如果您想使用 MMTweenAnimation 的最新代码,请使用
pod 'MMTweenAnimation', :head
有 10 种具体的动画类型
Back(回退) | Bounce(弹跳) | Circ(圆形) | Cubic(立方) | Elastic(弹性) |
---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
Expo(指数) | Quad(二次方) | Quart(四次方) | Quint(五次方) | Sine(正弦) |
---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
要应用 MMTweenAnimation,您必须通过以下方式对其进行配置:
@property (nonatomic, copy) MMTweenAnimationBlock animationBlock;
@property (nonatomic, assign) double fromValue;
@property (nonatomic, assign) double toValue;
@property (nonatomic, assign) double duration; //default: 0.3
@property (nonatomic, assign) MMTweenFunctionType functionType; //default: MMTweenFunctionBounce
@property (nonatomic, assign) MMTweenEasingType easingType; //default: MMTweenEasingOut
例如:
MMTweenAnimation *anim = [MMTweenAnimation animation];
anim.functionType = MMTweenFunctionBounce;
anim.easingType = MMTweenEasingOut;
anim.duration = 2.0f;
anim.fromValue = 0;
anim.toValue = 200;
anim.animationBlock = ^(double c,double d,double v,id target,MMTweenAnimation *animation)
{
//c: current time, from the beginning of animation
//d: duration, always bigger than c
//v: value, after the change at current time
UIView *t = (UIView*)target;
t.center = CGPointMake(t.x, v);
};
[targetView pop_addAnimation:anim forKey:@"center.y"];
v1.0 您可以自定义或直接使用它。
@interface MMTweenAnimation : POPCustomAnimation
@property (nonatomic, copy) MMTweenAnimationBlock animationBlock;
@property (nonatomic, assign) double fromValue;
@property (nonatomic, assign) double toValue;
@property (nonatomic, assign) double duration;
@property (nonatomic, assign) MMTweenFunctionType functionType;
@property (nonatomic, assign) MMTweenEasingType easingType;
+ (instancetype)animation;
@end