Easing圆环动画
Easing圆环动画

效果


源码
https://github.com/YouXianMing/Animations
//
// CircleView.h
// YXMWeather
//
// Created by XianMingYou on 15/11/12.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import <UIKit/UIKit.h>
#import "YXEasing.h" @interface CircleView : UIView /**
* 线条宽度
*/
@property (nonatomic) CGFloat lineWidth; /**
* 线条颜色
*/
@property (nonatomic, strong) UIColor *lineColor; /**
* 旋转方向
*/
@property (nonatomic) BOOL clockWise; /**
* 开始角度
*/
@property (nonatomic) CGFloat startAngle; /**
* 初始化view
*/
- (void)buildView; /**
* 做strokeEnd动画
*
* @param value 取值 [0, 1]
* @param func 函数指针
* @param animated 是否执行动画
* @param duration 动画持续的时间
*/
- (void)strokeEnd:(CGFloat)value animationType:(AHEasingFunction)func animated:(BOOL)animated duration:(CGFloat)duration; /**
* 做strokeStart动画
*
* @param value 取值 [0, 1]
* @param func 函数指针
* @param animated 是否执行动画
* @param duration 动画持续的时间
*/
- (void)strokeStart:(CGFloat)value animationType:(AHEasingFunction)func animated:(BOOL)animated duration:(CGFloat)duration; /**
* 便利构造器创建出实例对象
*
* @param frame frame值
* @param width 线条宽度
* @param color 线条颜色
* @param clockWise 是否是顺时钟
* @param angle 开始是否的角度(取值范围 0° ~ 360°)
*
* @return 实例对象
*/
+ (instancetype)circleViewWithFrame:(CGRect)frame
lineWidth:(CGFloat)width
lineColor:(UIColor *)color
clockWise:(BOOL)clockWise
startAngle:(CGFloat)angle; @end
//
// CircleView.m
// YXMWeather
//
// Created by XianMingYou on 15/11/12.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "CircleView.h" // 将度数转换为弧度
#define RADIAN(degrees) ((M_PI * (degrees))/ 180.f) // 将弧度转换为度数
#define DEGREES(radian) ((radian) * 180.f / M_PI) @interface CircleView () /**
* 圆形layer
*/
@property (nonatomic, strong) CAShapeLayer *circleLayer; @end @implementation CircleView /**
* 初始化frame值
*
* @param frame 尺寸值
*
* @return 实例对象
*/
- (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // 创建出layer
[self createCircleLayer];
} return self;
} /**
* 创建出layer
*/
- (void)createCircleLayer { self.circleLayer = [CAShapeLayer layer];
self.circleLayer.frame = self.bounds;
[self.layer addSublayer:self.circleLayer];
} /**
* 初始化view
*/
- (void)buildView { // 初始化信息
CGFloat lineWidth = (self.lineWidth <= ? : self.lineWidth);
UIColor *lineColor = (self.lineColor == nil ? [UIColor blackColor] : self.lineColor);
CGSize size = self.bounds.size;
CGFloat radius = size.width / .f - lineWidth / .f; // 设置半径(刚好贴到frame上面去) // 旋转方向
BOOL clockWise = self.clockWise;
CGFloat startAngle = ;
CGFloat endAngle = ;
if (clockWise == YES) { startAngle = -RADIAN( - self.startAngle);
endAngle = RADIAN( + self.startAngle); } else { startAngle = RADIAN( - self.startAngle);
endAngle = -RADIAN( + self.startAngle);
} // 创建出贝塞尔曲线
UIBezierPath *circlePath \
= [UIBezierPath bezierPathWithArcCenter:CGPointMake(size.height / .f, size.width / .f)
radius:radius
startAngle:startAngle
endAngle:endAngle
clockwise:clockWise]; // 获取path
self.circleLayer.path = circlePath.CGPath; // 设置颜色
self.circleLayer.strokeColor = lineColor.CGColor;
self.circleLayer.fillColor = [[UIColor clearColor] CGColor];
self.circleLayer.lineWidth = lineWidth;
self.circleLayer.strokeEnd = .f;
} - (void)strokeEnd:(CGFloat)value animationType:(AHEasingFunction)func animated:(BOOL)animated duration:(CGFloat)duration { // 过滤掉不合理的值
if (value <= ) { value = ; } else if (value >= ) { value = .f;
} if (animated) { // 关键帧动画
CAKeyframeAnimation *keyAnimation = [CAKeyframeAnimation animation];
keyAnimation.keyPath = @"strokeEnd";
keyAnimation.duration = duration;
keyAnimation.values = \
[YXEasing calculateFrameFromValue:self.circleLayer.strokeEnd
toValue:value
func:func
frameCount:duration * ]; // 执行动画
self.circleLayer.strokeEnd = value;
[self.circleLayer addAnimation:keyAnimation forKey:nil]; } else { // 关闭动画
[CATransaction setDisableActions:YES];
self.circleLayer.strokeEnd = value;
[CATransaction setDisableActions:NO];
}
} - (void)strokeStart:(CGFloat)value animationType:(AHEasingFunction)func animated:(BOOL)animated duration:(CGFloat)duration { // 过滤掉不合理的值
if (value <= ) { value = ; } else if (value >= ) { value = .f;
} if (animated) { // 关键帧动画
CAKeyframeAnimation *keyAnimation = [CAKeyframeAnimation animation];
keyAnimation.keyPath = @"strokeStart";
keyAnimation.duration = duration;
keyAnimation.values = \
[YXEasing calculateFrameFromValue:self.circleLayer.strokeStart
toValue:value
func:func
frameCount:duration * ]; // 执行动画
self.circleLayer.strokeStart = value;
[self.circleLayer addAnimation:keyAnimation forKey:nil]; } else { // 关闭动画
[CATransaction setDisableActions:YES];
self.circleLayer.strokeStart = value;
[CATransaction setDisableActions:NO];
}
} + (instancetype)circleViewWithFrame:(CGRect)frame
lineWidth:(CGFloat)width
lineColor:(UIColor *)color
clockWise:(BOOL)clockWise
startAngle:(CGFloat)angle { CircleView *circleView = [[CircleView alloc] initWithFrame:frame];
circleView.lineWidth = width;
circleView.lineColor = color;
circleView.clockWise = clockWise;
circleView.startAngle = angle; return circleView;
} @end
细节

Easing圆环动画的更多相关文章
- Swift - EasingAnimation绘制圆环动画
Swift - EasingAnimation绘制圆环动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CircleView ...
- Expression Blend实例中文教程(10) - 缓冲动画快速入门Easing
随着Rich Internet application(RIA)应用技术的发展,各个公司越来越注重于项目的用户体验性,在保证其功能完善,运行稳定的基础上,绚丽的UI和人性化的操作设计会给用户带来舒适的 ...
- 前端制作动画的几种方式(css3,js)
制作动态的网页是是前端工程师必备的技能,很好的实现动画能够极大的提高用户体验,增强交互效果,那么动画有多少实现方式,一直对此有选择恐惧症的我就总结一下,以便在开发的时候选择最好的实现方式. 1.css ...
- jQuery动画的实现
没有引入deferred机制,其余流程都有了 //////////// //创建动画缓动对象 // //////////// function Tween(value, prop, animation ...
- jQuery-1.9.1源码分析系列(十五) 动画处理
首先需要有队列(queue)的基本知识.见上一章. a.动画入口jQuery.fn.animate函数执行流程详解 先根据参数调用jQuery.speed获取动画相关参数,得到一个类似如下的对象:并且 ...
- jQuery-1.9.1源码分析系列(十五) 动画处理——缓动动画核心Tween
在jQuery内部函数Animation中调用到了createTweens()来创建缓动动画组,创建完成后的结果为: 可以看到上面的缓动动画组有四个原子动画组成.每一个原子动画的信息都包含在里面了. ...
- 读<jquery 权威指南>[3]-动画
一. 显示与隐藏——hide(),show() 1. 方法: hide(speed,[callback]); show(speed,[callback]); 说明:这两个方法还可以实现带动画效果的显示 ...
- Android 动画 setVisibility 后出错解决方法
===先说明下背景. 写的是个ListView 设置 adapter,并在列表末尾显示加载更多,点击 加载更多 时, 变成一个 圆环形的加载动画和 正在加载. 说明下,这个 加载动画是自己做得,一个圆 ...
- jQuery系列 第五章 jQuery框架动画特效
第五章 jQuery框架动画特效 5.1 jQuery动画特效说明 jQuery框架中为我们封装了众多的动画和特效方法,只需要调用对应的动画方法传递合适的参数,就能够方便的实现一些炫酷的效果,而且jQ ...
随机推荐
- mongo 运维管理学习
1 如何在线修改chunk大小 https://docs.mongodb.com/manual/tutorial/modify-chunk-size-in-sharded-cluster/ 2 chu ...
- python 库资源大全
偶然的机会翻到这篇文章,很全面,来源: Python 资源大全中文版 哪些 Python 库让你相见恨晚? 环境管理 管理 Python 版本和环境的工具 p:非常简单的交互式 pyth ...
- inotify 与 rsync文件同步实现与问题
首先分别介绍inotify 与 rsync的使用,然后用两者实现实时文件同步,最后说一下这样的系统存在什么样的问题. 1. inotify 这个具体使用网上很多,参考 inotify-tools 命令 ...
- 【LOJ】#2443. 「NOI2011」智能车比赛
题解 显然是个\(n^2\)的dp 我们要找每个点不穿过非赛道区域能到达哪些区域的交点 可以通过控制两条向量负责最靠下的上边界,和最靠上的下边界,检查当前点在不在这两条向量之间即可,对于每个点可以\( ...
- 【LOJ】#2320. 「清华集训 2017」生成树计数
题解 我,理解题解,用了一天 我,卡常数,又用了一天 到了最后,我才发现,我有个加法取模,写的是while(c >= MOD) c -= MOD 我把while改成if,时间,少了 六倍. 六倍 ...
- LoadRunner参数化取值与连接数据库
LoadRunner参数化取值与连接数据库 LoadRunner在使用参数化的时候,通常都是需要准备大数据量的,也因此LoadRunner提供两种参数化取值方式,一种是手动编辑,另一种就是通过连接 ...
- 二、 sql*plus常用命令
一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限,该用户 ...
- python io 模块之 open() 方法(好久没写博客了)
io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True),打开file ...
- [Arc079F] Namori Grundy
[Arc079F] Namori Grundy 题目大意: 一个有向弱联通环套树. 一个点的sg值等于出边连向点的sg值的mex. 试问是否有办法给每个点分配sg值? 试题分析 题目大意把一些难点跳过 ...
- 20162325 金立清 S2 W11 C20
20162325 2017-2018-2 <程序设计与数据结构>第11周学习总结 教材关键概念摘要 在哈希方法中,元素保存在哈希表中,其在表中的位置由哈希函数确定. 两个元素或关键字映射到 ...