POP动画[3]

简介:

POP动画[3]

这一节主要讲解POP动画的自定义动画属性.

POP动画中有一个参数,叫timingFunction,与CoreAnimation中的一个参数CAMediaTimingFunction基本一样,下图表示的是kCAMediaTimingFunctionEaseInEaseOut的曲线图.

下图是Spring动画效果:

我们可以使用自定义的属性来实现POP的库中没有提供的动画.

实现的效果:

源码:

//
//  RootViewController.m
//  YXPOP
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "RootViewController.h"
#import "POP.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor   = [UIColor blackColor];
    
    // 数值型label
    UILabel *numberLabel        = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    numberLabel.center                 = self.view.center;
    numberLabel.userInteractionEnabled = YES;
    numberLabel.textAlignment          = NSTextAlignmentCenter;
    numberLabel.textColor       = [UIColor redColor];
    numberLabel.text            = @"0";
    numberLabel.font            = [UIFont fontWithName:@"HelveticaNeue-UltraLight"
                                                  size:50.f];
    [self.view addSubview:numberLabel];
    
    // 添加手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                          action:@selector(tap:)];
    [numberLabel addGestureRecognizer:tap];

}

- (void)tap:(UITapGestureRecognizer *)tap
{
    UILabel *tmp                  = (UILabel *)tap.view;
    POPBasicAnimation *animation  = [POPBasicAnimation animation];
    animation.fromValue           = @([tmp.text intValue]);
    animation.toValue             = @(arc4random()%10000 + 2000);
    animation.duration            = 1.f;
    
    // 计算从fromValue到toValue插值的曲线
    animation.timingFunction      = \
        [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    // 将计算出来的值通过writeBlock动态给控件设定
    animation.property            = \
        [POPMutableAnimatableProperty propertyWithName:@"textLabel" initializer:^(POPMutableAnimatableProperty *prop) {
         prop.writeBlock      = ^(id obj, const CGFloat values[]) {
             UILabel *label   = (UILabel *)obj;
             NSNumber *number = @(values[0]);
             int num          = [number intValue];
             label.text       = [@(num) stringValue];
         };
     }];
    
    
    [tmp pop_addAnimation:animation forKey:@"numberLabelAnimation"];
}

@end

他们彼此间凌乱的关系如下所示:

duration代表x轴(时间轴)

fromValue与toValue代表y轴的最小值与最大值

timingFunction代表时间曲线(EaseOut曲线)

曲线中的每一个小点代表的是根据上述各个值计算出来的一个中间值,而这个中间值就是我们用来做动画而用的动画设定值.

以下网址是介绍如何设定CAMediaTimingFunction的(http://netcetera.org/camtf-playground.html).

目录
相关文章
SwiftUI—如何制作循环动画并指定动画的循环次数
SwiftUI—如何制作循环动画并指定动画的循环次数
517 0
SwiftUI—如何制作循环动画并指定动画的循环次数
|
9月前
pop() push() shift() unshift()作用
pop() push() shift() unshift()作用
|
存储 前端开发 JavaScript
JavaScript总结:关于堆栈、队列中push()、pop()、shift()、unshift()使用方法的理解
JavaScript总结:关于堆栈、队列中push()、pop()、shift()、unshift()使用方法的理解
190 0
JavaScript总结:关于堆栈、队列中push()、pop()、shift()、unshift()使用方法的理解
|
JavaScript 开发者
动画-使用 transition-group 元素实现列表动画|学习笔记
快速学习动画-使用 transition-group 元素实现列表动画
109 0
动画-使用 transition-group 元素实现列表动画|学习笔记
|
JavaScript 开发者
动画-使用transition-group元素实现列表动画|学习笔记
快速学习动画-使用transition-group元素实现列表动画
103 0
动画-使用transition-group元素实现列表动画|学习笔记
ScrollView push之后再pop回来,contentOffset变成了0
ScrollView push之后再pop回来,contentOffset变成了0
149 0
|
Spring Java
Facebook Pop 动画框架详细解析
Facebook Pop动画框架详细解析(一) —— 基本概览Facebook Pop动画框架详细解析(二) —— 基本架构Facebook Pop动画框架详细解析(三) —— spring动画简单实例Facebook Pop动画框架详细解析(四) —...
1480 0