POP数值动画

效果

源码

https://github.com/YouXianMing/Animations

//
// PopNumberController.m
// Animations
//
// Created by YouXianMing on 15/11/18.
// Copyright © 2015年 YouXianMing. All rights reserved.
// #import "PopNumberController.h"
#import "POPNumberAnimation.h"
#import "GCD.h"
#import "StringAttributeHelper.h" @interface PopNumberController () <POPNumberAnimationDelegate> @property (nonatomic, strong) POPNumberAnimation *numberAnimation;
@property (nonatomic, strong) GCDTimer *timer;
@property (nonatomic, strong) UILabel *label; @end @implementation PopNumberController - (void)viewDidLoad { [super viewDidLoad];
} - (void)setup { [super setup]; _label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
_label.textAlignment = NSTextAlignmentCenter;
_label.center = self.view.center;
[self.view addSubview:_label]; // Init numberAnimation.
self.numberAnimation = [[POPNumberAnimation alloc] init];
self.numberAnimation.delegate = self; // Timer event.
__weak PopNumberController *weakSelf = self;
self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
[self.timer event:^{ // Start animation.
[weakSelf configNumberAnimation];
[weakSelf.numberAnimation startAnimation]; } timeIntervalWithSecs:.f];
[self.timer start];
} - (void)configNumberAnimation { self.numberAnimation.fromValue = self.numberAnimation.currentValue;
self.numberAnimation.toValue = (arc4random() % / .f);
self.numberAnimation.duration = .f;
self.numberAnimation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.69 :0.11 :0.32 :0.88];
[self.numberAnimation saveValues];
} - (void)POPNumberAnimation:(POPNumberAnimation *)numberAnimation currentValue:(CGFloat)currentValue { // Init string.
NSString *numberString = [NSString stringWithFormat:@"%.1f", currentValue];
NSString *mpsString = @"mps";
NSString *totalString = [NSString stringWithFormat:@"%@ %@", numberString, mpsString]; // Init string ranges.
NSRange mpsRange = [totalString rangeOfString:mpsString];
NSRange numberRange = [totalString rangeOfString:numberString];
NSRange totalRange = NSMakeRange(, totalString.length); // Init attributes.
FontAttribute *totalFont = [FontAttribute new];
totalFont.font = Font_Avenir_Light(.f);
totalFont.effectRange = totalRange; FontAttribute *numberFont = [FontAttribute new];
numberFont.font = Font_HYQiHei(.f);
numberFont.effectRange = numberRange; ForegroundColorAttribute *totalColor = [ForegroundColorAttribute new];
totalColor.color = [UIColor blackColor];
totalColor.effectRange = totalRange; ForegroundColorAttribute *mpsColor = [ForegroundColorAttribute new];
mpsColor.color = [self mpsColorWithValue:currentValue / .f];
mpsColor.effectRange = mpsRange; ForegroundColorAttribute *numColor = [ForegroundColorAttribute new];
numColor.color = [self numColorWithValue:currentValue / .f];
numColor.effectRange = numberRange; // Create richString.
NSMutableAttributedString *richString = [[NSMutableAttributedString alloc] initWithString:totalString];
[richString addStringAttribute:totalFont];
[richString addStringAttribute:totalColor];
[richString addStringAttribute:numberFont];
[richString addStringAttribute:mpsColor];
[richString addStringAttribute:numColor]; _label.attributedText = richString;
} - (UIColor *)numColorWithValue:(CGFloat)value { return [UIColor colorWithRed:value green: blue: alpha:.f];
} - (UIColor *)mpsColorWithValue:(CGFloat)value { return [UIColor colorWithRed: green:value / .f blue:value / .f alpha:value];
} @end

细节

POP数值动画的更多相关文章

  1. iOS利用Runtime自定义控制器POP手势动画

    前言 苹果在iOS 7以后给导航控制器增加了一个Pop的手势,只要手指在屏幕边缘滑动,当前的控制器的视图就会跟随你的手指移动,当用户松手后,系统会判断手指拖动出来的大小来决定是否要执行控制器的Pop操 ...

  2. pop弹簧动画实现

    POP是一个在iOS与OS X上通用的极具扩展性的动画引擎.它在基本的静态动画的基础上增加的弹簧动画与衰减动画,使之能创造出更真实更具物理性的交互动画.POP的API可以快速的与现有的ObjC代码集成 ...

  3. POP缩放动画

    POP缩放动画 效果 源码 https://github.com/YouXianMing/Animations // // SpringScaleViewController.m // Animati ...

  4. POP按钮动画

    POP按钮动画 效果 源码 https://github.com/YouXianMing/Animations // // ButtonPressViewController.m // Faceboo ...

  5. 在SOUI3.0中使用数值动画

    上一篇介绍了插值动画,插值动画是直接作用于窗口对象的. 数值动画则可以作用于任何对象. SOUI内置了3种数值类型的动画,分别是SIntAnimator, SFloatAnimator, SColor ...

  6. POP简单动画简单使用 (入门级别)

    动画可以让APP“更友好”的与用户交互,苹果提供很多的好看的动画供开发者使用,不过简单的平移.旋转.缩放.......使用起来很简单,但是想要进行一些比较复杂的动画效果,使用起来就比较难以实现,俗话说 ...

  7. ios pop 折叠动画

    今天写了一个很有趣的电影太,我们可以去githoub下载. 这部动画是高级写作,我参考了它.而凝视,我希望你能看的懂. 各种动画.事实上,一些不起眼的开始.我也只是摸索. 我希望有更多的交流.[   ...

  8. Swift基础之自定义PUSH和POP跳转动画

    之前用OC代码写过PUSH和POP的转场动画,闲来无事,将其转换成Swift语言,希望对大家有帮助,转载请注明.... 如何实现PUSH和POP的转场动画? 首先,创建一个NSObject的类,分别用 ...

  9. POP介绍与使用实践(快速上手动画)[转]

    前言 动画在APP开发过程中 大家多多少少都会接触到 而且随着ios7的扁平化风格启用之后 越来越多的APP开始尝试加入各种绚丽的动画交互效果以增加APP的用户体验(当然 还是以国外的APP居多) 有 ...

随机推荐

  1. 一步一步学习IdentityServer3 (14) 启用Https

    申领一个CA证书,我用了一个腾讯的免费证书night-c.cn,这是腾讯云买域名送的一个证书 是单域名,非泛域名 1:安装证书  IIS选择证书 2:将证书加载到Identityserver3中,并启 ...

  2. 15 链表中倒数第k个结点

    输入一个链表,输出该链表中倒数第k个结点. p1先走k-1步,p1 p2再一起走 C++: /* struct ListNode { int val; struct ListNode *next; L ...

  3. Metronic4.7.5 下载 HTML5 UI后台管理框架

    Metronic 是一套精美的响应式后台管理模板,基于强大的 Twitter Bootstrap 3.3.4 框架实现.Metronic 拥有简洁优雅的 Metro UI 风格界面,6 种颜色可选,7 ...

  4. day7异常处理

    异常处理 下面看一个简单例子: data = {} try: data["name"] except KeyError as e: #e是错误的相信信息,错误的原因 print(& ...

  5. C语言:1孩半问题

    题目: 一孩半,又称独女户二胎,即中国大陆部分农村的一项计划生育政策,第一胎是女孩的夫妻可以生育第二个子女.如果第二胎有n%人工性别选择干预(选择男孩),试问男女比例为多少.(10分)题目内容: 一孩 ...

  6. [水煮 ASP.NET Web API2 方法论](3-1)集中式路由

    问题 怎样集中的定义路由 解决方案 通过调用 HttpRouteCollectionExtension 类中的 MapHttpRoute 扩展方法在 HttpRouteCollection 中定义路由 ...

  7. HTTP Status 500 - Request processing failed; nested exception is org.apache.ibatis.binding.BindingException

    在使用Maven工程管理工具整合SSM框架时,Mybatis使用逆向工程生成的pojo,mapper接口及映射文件,把mapper接口和映射文件放在DAO工程的同一级src/main/java目录下. ...

  8. 灵活的按键处理程序 FlexibleButton

    前言 正好工作中用到按键处理,需要处理单击.长按等按键事件,然后就造了这么一个轮子,为了以后更方便地加入其它的项目中使用,遂将其开源到 GitHub 中. 后面发现 RT-Thread 软件包里也有一 ...

  9. IDEA导入eclipse项目并部署运行完整步骤(转发)

    首先说明一下:idea里的project相当于eclipse里的workspace,而idea里的modules相当于eclipse里的project 1.File-->Import Proje ...

  10. 洛谷——P1231 教辅的组成

    P1231 教辅的组成 题目背景 滚粗了的HansBug在收拾旧语文书,然而他发现了什么奇妙的东西. 题目描述 蒟蒻HansBug在一本语文书里面发现了一本答案,然而他却明明记得这书应该还包含一份练习 ...