Swift - EasingAnimation绘制圆环动画
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绘制圆环动画的更多相关文章
- 第165天:canvas绘制圆环旋转动画
canvas绘制圆环旋转动画——面向对象版 1.HTML 注意引入Konva.js库 <!DOCTYPE html> <html lang="en"> &l ...
- 自己定义View之绘制圆环
一.RingView 自己定义的view,构造器必须重写,至于重写哪个方法,參考例如以下: ①假设须要改变View绘制的图像,那么须要重写OnDraw方法.(这也是最经常使用的重写方式.) ②假设须要 ...
- Swift - UITableView展开缩放动画
Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...
- Easing圆环动画
Easing圆环动画 效果 源码 https://github.com/YouXianMing/Animations // // CircleView.h // YXMWeather // // Cr ...
- canvas+js绘制序列帧动画+面向对象
效果: 素材: 源码:(一般的绘制方式) <!DOCTYPE html> <html lang="en"> <head> <meta ch ...
- Android 绘制圆环
使用画圆弧的方式绘制圆环和进度条,使用sweepGradient进行渐变. 参考链接 http://blog.csdn.net/u011494050/article/details/39251239 ...
- OpenGL学习进程(10)第七课:四边形绘制与动画基础
本节是OpenGL学习的第七个课时,下面以四边形为例介绍绘制OpenGL动画的相关知识: (1)绘制几种不同的四边形: 1)四边形(GL_QUADS) OpenGL的GL_QUADS图 ...
- 通通玩blend美工(8)——动态绘制路径动画,画出个萌妹子~
原文:通通玩blend美工(8)--动态绘制路径动画,画出个萌妹子~ 2年前我在玩Flex的时候就一直有一个疑问,就是如何来实现一个蚊香慢慢烧完的Loading动画呢? 刚经历了某甲方高强度一个月的洗 ...
- CSS3绘制弹球动画效果
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
随机推荐
- LeetCode(13):罗马数字转整数
Easy! 题目描述: 罗马数字包含以下七种字符:I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写 ...
- java Stack(栈)
"Stack" 通常时指"后进后出"(LIFO)的容器,有时栈也被称为叠加栈,因为最后"压入"栈的元素,第一个"弹出"栈 ...
- IDEA & Android Studio换主题背景
IDEA系列主题 http://www.riaway.com/index.phphttp://color-themes.com/?view=index 详细用法: https://www.jiansh ...
- 后缀自动机(SAM)速成手册!
正好写这个博客和我的某个别的需求重合了...我就来讲一讲SAM啦qwq 后缀自动机,也就是SAM,是一种极其有用的处理字符串的数据结构,可以用于处理几乎任何有关于子串的问题,但以学起来异常困难著称(在 ...
- 文件基本操作 (C语言)
一切皆文件 ---Linux 头文件 <stdio.h> 中定义了文件的相关操作 #include <stdio.h> 文件操作基本流程: 打开:fopen 相关操作 关闭:f ...
- 2017 JUST Programming Contest 2.0 题解
[题目链接] A - On The Way to Lucky Plaza 首先,$n>m$或$k>m$或$k>n$就无解. 设$p = \frac{A}{B}$,$ans = C_{ ...
- 003.SSH密钥对登陆
一 需求背景 master:172.24.8.30 client-01:172.24.8.31 client-01:172.24.8.32 client-01:172.24.8.33 在master上 ...
- 循序渐进学.Net Core Web Api开发系列【14】:异常处理
系列目录 循序渐进学.Net Core Web Api开发系列目录 本系列涉及到的源码下载地址:https://github.com/seabluescn/Blog_WebApi 一.概述 本篇介绍异 ...
- DBUtils工具
DBUtils工具 简介 是Apache旗下的产品.是对jdbc的简单封装.提供出通用的jdbc操作方法.简化开发者使用jdbc的成本. 常用的API说明 |- QueryRunner类: 主要进行j ...
- luoguP4705 玩游戏 分治FFT
\[ \begin{aligned} Ans(k) &= \sum \limits_{i = 1}^n \sum \limits_{j = 1}^m \sum \limits_{t = 0}^ ...