【axc】简单的线性动画绘制
在一个View上绘制一条直线 然后做出相应的动画效果 可以这样封装三个方法:
/**
* 划线工具
*
* @param lineArray 线段的点数组 NSValue 类型 默认第一个点为起点
* @param time 划线时间
* @param strokeColor 线段颜色
*/
- (void)axcBaseAniamtionWithLinePointArray:(NSArray <NSValue *> *)lineArray time:(CGFloat )time strokeColor:(UIColor *)strokeColor{
if (lineArray.count <= 1) {
if (_axcBasePrintLog) {
NSLog(@"%@:\n你的数组对象少于一个,无法划线!",self);
}
return;
}
if (_axcBasePrintLog) {
NSLog(@"%@:\n当前正在划线\t方法名:axcBaseAniamtionWithLinePointArray\t起点:%@\t划线时间:%.2f,颜色:%@\n",self,NSStringFromCGPoint([lineArray[0] CGPointValue]),time,strokeColor);
}
UIBezierPath *_path=[UIBezierPath bezierPath];
CGPoint point1 = [lineArray[0] CGPointValue];
[_path moveToPoint:point1];
for (int i = 1; i < lineArray.count; i ++) {
[_path addLineToPoint: [lineArray[i] CGPointValue]];
if (_axcBasePrintLog) {
NSLog(@"%@:遍历划线点(%d):%@\n",self,i + 1,NSStringFromCGPoint([lineArray[i] CGPointValue]));
}
}
CAShapeLayer *shapeLayer=[CAShapeLayer layer];
shapeLayer.path=_path.CGPath;
shapeLayer.fillColor=[UIColor clearColor].CGColor;//填充颜色
shapeLayer.strokeColor=strokeColor.CGColor;//边框颜色
[self.view.layer addSublayer:shapeLayer];
// 动画
CABasicAnimation *pathAniamtion = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
// 时间
pathAniamtion.duration = time;
pathAniamtion.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAniamtion.fromValue = [NSNumber numberWithFloat:0.0f];
// 划线段的百分之多少
pathAniamtion.toValue = [NSNumber numberWithFloat:1];
pathAniamtion.autoreverses = NO;
[shapeLayer addAnimation:pathAniamtion forKey:nil];
}
/**
* 圆规工具
*
* @param Center 中心点
* @param radius 半径
* @param startAngle 开始角度
* @param endAngle 结束角度
* @param clockwise 是否顺时针
* @param time 作图时间
* @param strokeColor 颜色
*/
- (void)axcBaseAniamtionArcWithCenter:(CGPoint )Center
radius:(CGFloat )radius
startAngle:(CGFloat )startAngle
endAngle:(CGFloat )endAngle
clockwise:(BOOL )clockwise
time:(CGFloat )time
strokeColor:(UIColor *)strokeColor{
UIBezierPath *_path=[UIBezierPath bezierPath];
[_path addArcWithCenter:Center radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise];
CAShapeLayer *shapeLayer=[CAShapeLayer layer];
shapeLayer.path=_path.CGPath;
shapeLayer.fillColor=[UIColor clearColor].CGColor;//填充颜色
shapeLayer.strokeColor=strokeColor.CGColor;//边框颜色
[self.view.layer addSublayer:shapeLayer];
// 动画
CABasicAnimation *pathAniamtion = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
// 时间
pathAniamtion.duration = time;
pathAniamtion.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAniamtion.fromValue = [NSNumber numberWithFloat:0.0f];
// 划线段的百分之多少
pathAniamtion.toValue = [NSNumber numberWithFloat:1];
pathAniamtion.autoreverses = NO;
[shapeLayer addAnimation:pathAniamtion forKey:nil];
}
/**
* 清除所有划线
*/
- (void)axcBaseClearAllShapeLayer{
if (_axcBasePrintLog) {
NSLog(@"%@:\n当前执行清除该界面上的所有划线!",self);
}
NSArray *shapeLayerArray = self.view.layer.sublayers;
for (int i = 0; i < shapeLayerArray.count; i ++) {
if ([shapeLayerArray[i] isKindOfClass:[CAShapeLayer class]]) {
[shapeLayerArray[i] removeFromSuperlayer];
}
}
}
【axc】简单的线性动画绘制的更多相关文章
- iOS 动画绘制线条颜色渐变的折线图
效果图 .................... 概述 现状 折线图的应用比较广泛,为了增强用户体验,很多应用中都嵌入了折线图.折线图可以更加直观的表示数据的变化.网络上有很多绘制折线图的demo,有 ...
- 重新想象 Windows 8 Store Apps (19) - 动画: 线性动画, 关键帧动画, 缓动动画
原文:重新想象 Windows 8 Store Apps (19) - 动画: 线性动画, 关键帧动画, 缓动动画 [源码下载] 重新想象 Windows 8 Store Apps (19) - 动画 ...
- 基于Babylon.js编写简单的骨骼动画生成器
使用骨骼动画技术可以将网格的顶点分配给若干骨头,通过给骨头设定关键帧和父子关系,可以赋予网格高度动态并具有传递性的变形 效果.这里结合之前的相关研究在网页端使用JavaScript实现了一个简单的骨骼 ...
- 用react的ReactCSSTransitionGroup插件实现简单的弹幕动画
1,开始的思路 公司想做直播方面的项目,并想加入弹幕的功能,直播的页面已经作为一个组件放在了用react+redux写好的一个网站项目上.所以技术老大让我研究下如何用react实现弹幕的功能.下面我就 ...
- 背水一战 Windows 10 (14) - 动画: 线性动画, 关键帧动画
[源码下载] 背水一战 Windows 10 (14) - 动画: 线性动画, 关键帧动画 作者:webabcd 介绍背水一战 Windows 10 之 动画 线性动画 - ColorAnimatio ...
- c语言描述简单的线性表,获取元素,删除元素,
//定义线性表 #define MAXSIZE 20 typedef int ElemType; typedef struct { ElemType data[MAXSIZE]; //这是数组的长度, ...
- Android简单逐帧动画Frame的实现(二)
Android简单逐帧动画Frame的实现 Android简单逐帧动画Frame的实现 1.逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影. 2.实现步骤: 1. 在工程里 ...
- WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法。
原文:WPF编程,通过KeyFrame 类型制作控件线性动画的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/articl ...
- 用path动画绘制水波纹
用path动画绘制水波纹 效果 源码 // // ViewController.m // PathAnimation // // Created by YouXianMing on 15/7/3. / ...
随机推荐
- Redis执行Lua脚本示例
Redis在2.6推出了脚本功能,允许开发者使用Lua语言编写脚本传到Redis中执行.使用脚本的好处如下: 1.减少网络开销:本来5次网络请求的操作,可以用一个请求完成,原先5次请求的逻辑放在red ...
- BZOJ 1412 & 最小割
什么时候ZJ省选再现一次这么良心的题吧... 题意: 在一个染色的格子画分割线,使其不想连,求最少的线段 SOL: 裸裸的最小割.题目要求两种颜色不想连,我们把他分到两个集合,也就是把所有相连的边切断 ...
- Darkest page of my coding life
The code i wrote a while ago recently caused a disaster and as I reviewed it I found it is the silli ...
- Android js相互调用
一.webview相当于android中的浏览器,基于webkit开发,可以浏览网页文件,支持css javas cript 以及html webview.getSettings().setJavaS ...
- 【CodeVS】 p1077 多源最短路
题目描述 Description 已知n个点(n<=100),给你n*n的方阵,a[i,j]表示从第i个点到第j个点的直接距离. 现在有Q个询问,每个询问两个正整数,a和b,让你求a到b之间的最 ...
- SQL2043N 与 linux的randomize_va_space特性
自从数据库服务器从redhat4.6升级到redhat5.5之后,在使用TSM备份的时候偶尔会出现SQL2043N 查看错误: [db2inst1@limt ~]$ db2 ? SQL2043N S ...
- “Invalid maximum heap size” when running Maven
运行mvn package,报错: Invalid maximum heap size: -Xmx512m. Error: Could not create the Java Virtual Mach ...
- AJAX.JSONP 跨域
var Request = { timeout: 10 * 1000, // 10秒超时 status: 10, statusenum: { Wait: 10 ...
- #define is unsafe——I
I. #define is unsafe Have you used #define in C/C++ code like the code below? #include <stdio.h&g ...
- REST
REST (REpresentational State Transfer). 为REST模式的Web服务与复杂的SOAP和XML-RPC对比来讲明显的更加简洁. "设计良好的网络应用表现为 ...