swift之水纹动画
import UIKit
class CVLayerView: UIView {
var pulseLayer : CAShapeLayer! //定义图层
override init(frame: CGRect) {
super.init(frame: frame)
let width = self.bounds.size.width
// 动画图层
pulseLayer = CAShapeLayer()
pulseLayer.bounds = CGRect(x: 0, y: 0, width: width, height: width)
pulseLayer.position = CGPoint(x: width/2, y: width/2)
pulseLayer.backgroundColor = UIColor.clear.cgColor
// 用BezierPath画一个原型
pulseLayer.path = UIBezierPath(ovalIn: pulseLayer.bounds).cgPath
// 脉冲效果的颜色 (注释*1)
pulseLayer.fillColor = UIColor.init(r: 213, g: 54, b: 13).cgColor
pulseLayer.opacity = 0.0
// 关键代码
let replicatorLayer = CAReplicatorLayer()
replicatorLayer.bounds = CGRect(x: 0, y: 0, width: width, height: width)
replicatorLayer.position = CGPoint(x: width/2, y: width/2)
replicatorLayer.instanceCount = 3 // 三个复制图层
replicatorLayer.instanceDelay = 1 // 频率
replicatorLayer.addSublayer(pulseLayer)
self.layer.addSublayer(replicatorLayer)
self.layer.insertSublayer(replicatorLayer, at: 0)
}
func starAnimation() {
// 透明
let opacityAnimation = CABasicAnimation(keyPath: "opacity")
opacityAnimation.fromValue = 1.0 // 起始值
opacityAnimation.toValue = 0 // 结束值
// 扩散动画
let scaleAnimation = CABasicAnimation(keyPath: "transform")
let t = CATransform3DIdentity
scaleAnimation.fromValue = NSValue(caTransform3D: CATransform3DScale(t, 0.0, 0.0, 0.0))
scaleAnimation.toValue = NSValue(caTransform3D: CATransform3DScale(t, 1.0, 1.0, 0.0))
// 给CAShapeLayer添加组合动画
let groupAnimation = CAAnimationGroup()
groupAnimation.animations = [opacityAnimation,scaleAnimation]
groupAnimation.duration = 3 //持续时间
groupAnimation.autoreverses = false //循环效果
groupAnimation.repeatCount = HUGE
groupAnimation.isRemovedOnCompletion = false
pulseLayer.add(groupAnimation, forKey: nil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
使用方法
let waveView = CVLayerView(frame: CGRect(x: margin*CGFloat(index)*2+margin/2, y: 10, width: margin, height: margin))
waveView.center = button.center
// 因为我的VC是XIB 所以将图层添加在到按钮之下 一般用法就直接addSubview就可以了
// self.insertSubview(waveView, belowSubview: button)
self.addSubview(waveView)
waveView.starAnimation() // 开始动画
swift之水纹动画的更多相关文章
- Swift - transform.m34动画示例
Swift - transform.m34动画示例 效果 源码 https://github.com/YouXianMing/Swift-Animations // // CATransform3DM ...
- Swift 表视图动画教程: Drop-In Cards
http://www.raywenderlich.com/76024/swift-table-view-animations-tutorial-drop-cards 标准 table view 是一个 ...
- swift - 歌曲列表动画
// // ViewController.swift // songAnimation // // Created by su on 15/12/10. // Copyright © 2015 ...
- iOS开发——动画篇Swift篇&常用动画总结
UIView动画: UIView动画时最基本的动画,是直接对我们界面上控件进行简单的动画效果实现,如果你只需要用到一些简单的效果,那么这个很适合你,关于UIView动画实现恨简单, UIKit直接将动 ...
- swift 之SnapKit 动画
这个问题纠结了我挺长时间的.一直以为把约束直接添加到动画里面就可以了.但是并没那么简单.-.-其实还是挺简 class ViewController: UIViewController { @IBOu ...
- swift 头尾式动画
1.0 头尾式动画 UIView.beginAnimations(nil, context: nil) UIView.setAnimationDuration(1.0) // 设置执行动画所需要的时间 ...
- swift 设置图片动画组 iOS11之前 默认图片 设置不成功
在iOS 11 上, 1.先执行动画组 在设置图片执行帧动画,2.先设置图片在设置帧动画,执行帧动画 没有任何问题 在iOS 10和iOS9上,必须 执行 方法二(先设置图片在设置帧动画,执行帧动画 ...
- 你会用swift创建复杂的加载动画吗(1)
时至今日,iOS 应用商店已经拥有超过了140万 应用,让你自己的应用脱颖而出确实是个不小的挑战.不过,在你的应用掉入默默无闻的大黑洞之前,你拥有一个小小的机遇窗,它能帮你吸引用户的注意. AD: 时 ...
- iOS - 开源框架、项目和学习资料汇总(动画篇)
动画 1. Core Animation笔记,基本的使用方法 – Core Animation笔记,基本的使用方法:1.基本动画,2.多步动画,3.沿路径的动画,4.时间函数,5.动画组.2. awe ...
随机推荐
- Lesson 46 Hobbies
Who, according to the authour, are 'Fortune's favoured children'? A gifted American psychologist has ...
- Vivado ILA观察信号和调试过程
先简单介绍一下ILA(Integrated Logic Analyzer)生成方法.这里有两种办法完成Debug Core的配置和实现. 方法一.mark_debug综合选项+Set Up Debug ...
- 第十届蓝桥杯 RSA解密(C++/ java)
一道不错的题目,借鉴了网上的代码,用了拓展欧几里得算法求逆元,再用快速乘求每次a的余数,再快速幂对余数进行幂运算. #include <bits/stdc++.h> using names ...
- 8051单片机中访问int中字节的方法
在使用单片机中,unsigned int 占2个字节,unsigned char 占一个字节.而单片机是实行的字节寻址.16字节的bit寻址实在是不好用, 不好用在不能建数组. 在实际的开发过程中,要 ...
- LOJ #10002. 喷水装置
题目 裸的贪心. 基本思想见图: Code: #include<iostream> #include<cstdio> #include<cstring> #incl ...
- 采用FLAG_ACTIVITY_CLEAR_TOP退出整个程序(多activity)
问题: 多activity中退出整个程序,例如从A->B->C->D,这时我需要从D直接退出程序. 网上资料:{ finish()和system(0)都只能退出单个activity. ...
- 剑指offer 按之字型顺序打印二叉树
题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 使用两个栈进行存储,我们在打印某一行节点 ...
- Linux基础命令、软件安装
常用命令 查看当前系统中存在哪些shell cat /etc/shells [root@** ~]# cat /etc/shells /bin/sh /bin/bash /usr/bin/sh /us ...
- 7.6 CLI 管理Varnish
./varnishd -f /usr/common/varnish/etc/varnish/ -a 测试: 代理tomcat服务器地址:http://172.20.10.5:1111/ telnet ...
- thread.start和threadstart.invoke的区别
new Thread(() =>refreshDGVdelegate(App.StockList)).Start();//在新线程中执行操作 new ThreadStart(() => r ...