• [翻译] RBBAnimation,让你使用关键帧动画更便利


    RBBAnimation

    RBBAnimation is a subclass of CAKeyframeAnimation that allows you to declare your animations using blocks instead of writing out all the individual key-frames.

    This gives you greater flexibility when specifying your animations while keeping your code concise.

    It comes out of the box with a replacement for CASpringAnimationsupport for custom easing functions such as bouncing as well as hooks to allow your writing your own animations fully from scratch.

    RBBAnimation继承自CAKeyframeAnimation,允许你在block中设置你所需要的动画属性,而不是在外面单独的写键值对。当你既想着要实现动画效果,又想保持你的代码看起来清爽,毫无疑问RBBAnimation是你不二的选择。

    Installation(安装

    To install RBBAnimation, I recommend the excellent CocoaPods. Simply add this to your Podfile

    pod 'RBBAnimation', '0.3.0'
    

    and you are ready to go!

    If you'd like to run the bundled test app, make sure to install its dependencies by running

    pod install
    

    after cloning the repo.

    我建议你使用CocoaPods安装吧。

    RBBCustomAnimation(自定义动画

    Use RBBCustomAnimation to create arbitrary animations by passing in an RBBAnimationBlock:

    使用RBBCustomAnimation来创建直观的自定义动画,在RBBAnimationBlock中设置即可。

    RBBCustomAnimation *rainbow = [RBBCustomAnimation animationWithKeyPath:@"backgroundColor"];
    
    rainbow.animationBlock = ^(CGFloat elapsed, CGFloat duration) {
        UIColor *color = [UIColor colorWithHue:elapsed / duration
                                    saturation:1
                                    brightness:1
                                         alpha:1];
    
        return (id)color.CGColor;
    };
    

    The arguments of the block are the current position of the animation as well as its total duration.

    Most of the time, you will probably want to use the higher-level RBBTweenAnimation.

    block中的参数就是你要设置动画的参数,以及需要你配置一个动画持续的时间。

    大部分时间,你需要使用更高级别上的RBBTweenAnimation。

    RBBSpringAnimation(精灵动画

    RBBSpringAnimation is a handy replacement for the private CASpringAnimation. Specify your spring's mass, damping, stiffness as well as its initial velocity and watch it go:

    RBBSpringAnimation是用来替换这个私有方法CASpringAnimation。指定你精灵对象的质量,阻尼,生硬程度以及他的速率,参考如下:

    RBBSpringAnimation *spring = [RBBSpringAnimation animationWithKeyPath:@"position.y"];
    
    spring.fromValue = @(-100.0f);
    spring.toValue = @(100.0f);
    spring.velocity = 0;
    spring.mass = 1;
    spring.damping = 10;
    spring.stiffness = 100;
    
    spring.additive = YES;
    spring.duration = [spring durationForEpsilon:0.01];
    

    RBBTweenAnimation(两点之间的动画

    RBBTweenAnimation allows you to animate from one value to another, similar to CABasicAnimation but with a greater flexibility in how the values should be interpolated.

    It supports the same cubic Bezier interpolation that you get from CAMediaTimingFunction using the RBBCubicBezier helper function:

    RBBTweenAnimation允许你从一个值动态变化到另外一个值,就像CABasicAnimation一样,但是呢,对于如何设置参数更加便利。

    它同样支持你篡改立方体贝塞尔曲线,你可以从CAMediaTimingFunction中使用RBBCubicBezier来获取一些帮助信息:

    RBBTweenAnimation *easeInOutBack = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
    
    easeInOutBack.fromValue = @(-100.0f);
    easeInOutBack.toValue = @(100.0f);
    easeInOutBack.easing = RBBCubicBezier(0.68, -0.55, 0.265, 1.55);
    
    easeInOutBack.additive = YES;
    easeInOutBack.duration = 0.6;
    

    However, RBBTweenAnimation also supports more complex easing functions such as RBBEasingFunctionEaseOutBounce:

    当然,RBBTweenAnimation支持更复杂的easing方法,例如RBBEasingFunctionEaseOutBounce:

    RBBTweenAnimation *bounce = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
    bounce.fromValue = @(-100);
    bounce.toValue = @(100);
    bounce.easing = RBBEasingFunctionEaseOutBounce;
    
    bounce.additive = YES;
    bounce.duration = 0.8;
    

    You can also specify your own easing functions, from scratch:

    你也可以使用你自己定制的easiing函数:

    RBBTweenAnimation *sinus = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
    sinus.fromValue = @(0);
    sinus.toValue = @(100);
    
    sinus.easing = ^CGFloat (CGFloat fraction) {
        return sin((fraction) * 2 * M_PI);
    };
    
    sinus.additive = YES;
    sinus.duration = 2;

  • 相关阅读:
    openSUSE 13.1 Milestone 4 发布
    Neo4j 2.0 M4 发布
    iBoxDB for .NET v1.5发布, 移动NoSQL数据库
    GNU libc (Glibc) 2.18 发布
    Android 开源项目维护者宣布退出
    Jeasyframe 开源框架 稳定版 V1.5 发布
    Spring Mobile 1.1.0.RC1 和 1.0.2 发布
    Deis logo 开源PaaS系统 Deis
    EasyCriteria 3.0 发布
    TypeScript 0.9.1 发布,新增 typeof 关键字
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3647909.html
Copyright © 2020-2023  润新知