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. jquery插件使用记录

    1.imgPreview(图片预览功能插件) demo地址:http://james.padolsey.com/demos/imgPreview/full/

  2. 流程设计器jQuery + svg/vml(Demo7 - 设计器与引擎及表单一起应用例子)

    去年就完成了流程设计器及流程引擎的开发,本想着把流程设计器好好整理一下,形成一个一步一步的开发案例,结果才整理了一点点,发现写文章比写代码还累,加上有事情要忙,结果就.. 明天要去外包驻场了,现把流程 ...

  3. ESLint处理

    当有遇到下划线的问题,会提示有问题,无法通过检测 需要在代码的前面加入以下代码就可以解决,地址是:https://stackoverflow.com/questions/44126983/eslint ...

  4. Eclipse反编译插件的安装

    步骤: 1.已经安装了Eclipse,如我的Eclipse目录:C:\Programs\JAVA\eclipse 2.反编译插件包:eclipse 反编译插件 jad 3.3.0.zip 3.解压反编 ...

  5. ECSHOP的JS文件代入问题

    参考一下默认的js写法就行了<script type='text/javascript' src='themes/ecmoban/js/jquery-1.7.2.min.js'></ ...

  6. Java_常用API

    1.基本类型包装类 1.1 概述 在实际程序使用中,程序界面上用户输入的数据都是以字符串类型进行存储的.而程序开发中,我们需要把字符串数据,根据需求转换成指定的基本数据类型,如年龄需要转换成int类型 ...

  7. My blog in AI -- 梯度下降算法

    人工神经网络是对生物神经网络的模仿,神经网络对一个问题的学习,需要经历数据输入.网络参数的训练.超参数的调节等部分. 这次我们来详细讨论一下神经网络的学习过程. 假设我们要训练一个神经网络去识别一张图 ...

  8. zoj 3983 Crusaders Quest 思维+枚举

    题目链接 这道题意思是: 给你一个长度为9的字符串,且只有3个a.3个g.3个o 问,你可以选择删除一段连续的串或者单个的字符也可以不删,最多会出现几个三子相连的子串 比如:agoagoago只有将两 ...

  9. python opencv3 背景分割 mog2 knn

    git:https://github.com/linyi0604/Computer-Vision 使用mog2算法进行背景分割 # coding:utf-8 import cv2 # 获取摄像头对象 ...

  10. 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut

    题意:平面上n个点,每个点带有一个或正或负的权值,让你在平面上放一个内边长为2l,外边长为2r的正方形框,问你最大能圈出来的权值和是多少? 容易推出,能框到每个点的 框中心 的范围也是一个以该点为中心 ...