Swift - EasingAnimation绘制圆环动画

效果

源码

https://github.com/YouXianMing/Swift-Animations

//
// CircleView.swift
// Swift-Animations
//
// Created by YouXianMing on 16/8/16.
// Copyright © 2016年 YouXianMing. All rights reserved.
// import UIKit // MARK: Public class : CircleView class CircleView: UIView { // MARK: Convenience init. convenience init(frame: CGRect, lineWidth : CGFloat, lineColor : UIColor, clockWise : Bool, startDegree : CGFloat) { self.init(frame : frame)
self.lineWidth = lineWidth
self.lineColor = lineColor
self.clockWise = clockWise
self.startDegree = startDegree
self.makeEffective()
} // MARK: Properties. /// Line width, default is 1.0.
var lineWidth : CGFloat { get { if pLineWidth <= { return } else {return pLineWidth}}
set(newVal) { pLineWidth = newVal}
} /// Line color, default is black color.
var lineColor : UIColor { get { if pLineColor == nil { return UIColor.blackColor()} else {return pLineColor}}
set(newVal) { pLineColor = newVal}
} /// Clock wise or not, default is true.
var clockWise : Bool = true /// Start degrees (0° ~ 360°), default is 0.
var startDegree : CGFloat = // MARK: Methods. /**
Make the config effective, when you set all the properties, you must run this method to make the config effective.
*/
func makeEffective() { let size = bounds.size
let radius = size.width / 2.0 - lineWidth / 2.0 var tmpStartAngle : CGFloat
var tmpEndAngle : CGFloat if clockWise == true { tmpStartAngle = -radianFromDegrees( - startDegree)
tmpEndAngle = radianFromDegrees( + startDegree) } else { tmpStartAngle = radianFromDegrees( - startDegree)
tmpEndAngle = -radianFromDegrees( + startDegree)
} let circlePath = UIBezierPath(arcCenter: CGPointMake(size.height / , size.width / ),
radius: radius, startAngle: tmpStartAngle, endAngle: tmpEndAngle, clockwise: clockWise)
pCircleLayer.path = circlePath.CGPath
pCircleLayer.fillColor = UIColor.clearColor().CGColor
pCircleLayer.strokeColor = lineColor.CGColor
pCircleLayer.lineWidth = lineWidth
pCircleLayer.strokeEnd =
} /**
Stroke start animation. - parameter value: StrokeStart value, range is [0, 1].
- parameter easingFunction: Easing function enum value.
- parameter animated: Animated or not.
- parameter duration: The animation's duration.
*/
func strokeStart(value : Double, easingFunction : EasingFunction, animated : Bool, duration : NSTimeInterval) { var strokeStartValue = value if strokeStartValue <= { strokeStartValue = } else if strokeStartValue >= { strokeStartValue =
} if animated == true { let easingValue = EasingValue(withFunction: easingFunction, frameCount: Int(duration * 60.0))
let keyAnimation = CAKeyframeAnimation(keyPath: "strokeStart")
keyAnimation.duration = duration
keyAnimation.values = easingValue.frameValueWith(fromValue: Double(pCircleLayer.strokeStart), toValue: strokeStartValue) pCircleLayer.strokeStart = CGFloat(strokeStartValue)
pCircleLayer.addAnimation(keyAnimation, forKey: nil) } else { CATransaction.setDisableActions(true)
pCircleLayer.strokeStart = CGFloat(strokeStartValue)
CATransaction.setDisableActions(false)
}
} /**
Stroke end animation. - parameter value: StrokeEnd value, range is [0, 1].
- parameter easingFunction: Easing function enum value.
- parameter animated: Animated or not.
- parameter duration: The animation's duration.
*/
func strokeEnd(value : Double, easingFunction : EasingFunction, animated : Bool, duration : NSTimeInterval) { var strokeStartValue = value if strokeStartValue <= { strokeStartValue = } else if strokeStartValue >= { strokeStartValue =
} if animated == true { let easingValue = EasingValue(withFunction: easingFunction, frameCount: Int(duration * 60.0))
let keyAnimation = CAKeyframeAnimation(keyPath: "strokeEnd")
keyAnimation.duration = duration
keyAnimation.values = easingValue.frameValueWith(fromValue: Double(pCircleLayer.strokeEnd), toValue: strokeStartValue) pCircleLayer.strokeEnd = CGFloat(strokeStartValue)
pCircleLayer.addAnimation(keyAnimation, forKey: nil) } else { CATransaction.setDisableActions(true)
pCircleLayer.strokeEnd = CGFloat(strokeStartValue)
CATransaction.setDisableActions(false)
}
} // MARK: Private value & func & system method. override init(frame: CGRect) { super.init(frame: frame)
pCircleLayer = CAShapeLayer()
pCircleLayer.frame = bounds
layer.addSublayer(pCircleLayer)
} required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented")
} private var pCircleLayer : CAShapeLayer!
private var pLineWidth : CGFloat! =
private var pLineColor : UIColor! = UIColor.blackColor() private func radianFromDegrees(degrees : CGFloat) -> CGFloat { return (CGFloat(M_PI) * degrees) / 180.0
}
}

Swift - EasingAnimation绘制圆环动画的更多相关文章

  1. 第165天:canvas绘制圆环旋转动画

    canvas绘制圆环旋转动画——面向对象版 1.HTML 注意引入Konva.js库 <!DOCTYPE html> <html lang="en"> &l ...

  2. 自己定义View之绘制圆环

    一.RingView 自己定义的view,构造器必须重写,至于重写哪个方法,參考例如以下: ①假设须要改变View绘制的图像,那么须要重写OnDraw方法.(这也是最经常使用的重写方式.) ②假设须要 ...

  3. Swift - UITableView展开缩放动画

    Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...

  4. Easing圆环动画

    Easing圆环动画 效果 源码 https://github.com/YouXianMing/Animations // // CircleView.h // YXMWeather // // Cr ...

  5. canvas+js绘制序列帧动画+面向对象

    效果: 素材: 源码:(一般的绘制方式) <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  6. Android 绘制圆环

    使用画圆弧的方式绘制圆环和进度条,使用sweepGradient进行渐变. 参考链接 http://blog.csdn.net/u011494050/article/details/39251239 ...

  7. OpenGL学习进程(10)第七课:四边形绘制与动画基础

        本节是OpenGL学习的第七个课时,下面以四边形为例介绍绘制OpenGL动画的相关知识:     (1)绘制几种不同的四边形: 1)四边形(GL_QUADS) OpenGL的GL_QUADS图 ...

  8. 通通玩blend美工(8)——动态绘制路径动画,画出个萌妹子~

    原文:通通玩blend美工(8)--动态绘制路径动画,画出个萌妹子~ 2年前我在玩Flex的时候就一直有一个疑问,就是如何来实现一个蚊香慢慢烧完的Loading动画呢? 刚经历了某甲方高强度一个月的洗 ...

  9. CSS3绘制弹球动画效果

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

随机推荐

  1. 【hadoop】har://

    来源:http://hadoop.apache.org/docs/r1.0.4/cn/hadoop_archives.html 在hadoop代码中发现了一个很奇怪的路径,由har://开头.经查询, ...

  2. Java编程的逻辑 (67) - 线程的基本协作机制 (上)

    ​本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...

  3. Android 插件化 开发

    插件化知识详细分解及原理 之Binder机制https://blog.csdn.net/yulong0809/article/details/56841993 插件化知识详细分解及原理 之代理,hoo ...

  4. 【LOJ】#2111. 「JLOI2015」战争调度

    题解 记录一个数组dp[i][S][k]表示第i个点,它上面所有的点的状态(参军或者后勤)可以用状态S来表示,一共有k个平民参军的最大收益,当然数组开不下,可以用vector动态开 我们对于每个平民枚 ...

  5. java集合类TreeMap和TreeSet

    看这篇博客前,可以先看下下列这几篇博客 Red-Black Trees(红黑树)                                         (TreeMap底层的实现就是用的红黑 ...

  6. 线性回归模型的 MXNet 与 TensorFlow 实现

    本文主要探索如何使用深度学习框架 MXNet 或 TensorFlow 实现线性回归模型?并且以 Kaggle 上数据集 USA_Housing 做线性回归任务来预测房价. 回归任务,scikit-l ...

  7. muduo学习笔记(二)Reactor关键结构

    目录 muduo学习笔记(二)Reactor关键结构 Reactor简述 什么是Reactor Reactor模型的优缺点 poll简述 poll使用样例 muduo Reactor关键结构 Chan ...

  8. CodeForces 794 G.Replace All

    CodeForces 794 G.Replace All 解题思路 首先如果字符串 \(A, B\) 没有匹配,那么二元组 \((S, T)\) 合法的一个必要条件是存在正整数对 \((x,y)\), ...

  9. 【11.1校内测试】【快速幂DP】【带权并查集】【模拟】

    Solution $jzy$大佬用了给的原根的信息,加上矩阵快速幂150行QAQ 然而$yuli$大佬的做法不仅好懂,代码只有50行! 快速幂的思想,把m看成要组成的区间总长度,每次将两段组合得到新的 ...

  10. UVALive 6908 Electric Bike dp

    Electric Bike 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8 ...