CAReplicatorLayer的使用
来源:互联网 发布:蚁群算法的实现 编辑:程序博客网 时间:2024/06/04 20:06
CAReplicatorLayer可以创建layer的的指定份数的子层(源层),每个副本可能有应用于其的几何,时间和颜色转换。CAReplicatorLayer可以嵌套使用。
hitTest:目前仅测试z replicator层的子层的第一个实例。
1.设置实例显示属性:
instanceCount:要创建的副本数,包括源层。默认为1
instanceDelay:指定复制副本之间的延迟(以秒为单位)动画。
instanceTransform:应用于前一个实例以产生当前实例的变换矩阵动画。该变换矩阵被应用于实例k-1以产生实例k。 矩阵相对于该层的中心被施加。默认为单位矩阵。
2.修改实例层几何样式属性:
preservesDepth:定义该层是否将其子层平坦到其平面上。默认为NO。
3.访问实例颜色值属性:
instanceColor:定义用于指定源对象的颜色。Animatable。默认为不透明白色。
instanceRedOffset:定义添加到每个复制实例的颜色的红色分量的偏移量。Animatable。将instanceRedOffset添加到实例k-1的红色分量,以产生实例k的调制颜色。
instanceGreenOffset:定义添加到每个复制实例的颜色的绿色分量的偏移量。Animatable。将instanceGreenOffset添加到实例k-1的红色分量,以产生实例k的调制颜色。
instanceBlueOffset:略(同上)
instanceAlphaOffset:略(同上)
4.使用案例:
case1:
代码:
func animation_1(){
let lay = CAReplicatorLayer()
lay.bounds =CGRect(x:0, y:0, width:320, height:320)
lay.position =view.center
lay.backgroundColor =UIColor.clear.cgColor
view.layer.addSublayer(lay)
let redSquare = CALayer()
redSquare.backgroundColor =UIColor.white.cgColor
redSquare.frame =CGRect(x:0, y:0, width:40, height:40)
let instanceCount = 5
lay.instanceCount = instanceCount
lay.instanceTransform =CATransform3DMakeTranslation(50,0,0)
let offsetStep = -1 / Float(instanceCount)
lay.instanceBlueOffset = offsetStep
lay.instanceGreenOffset = offsetStep
lay.addSublayer(redSquare)
}
case 2:(嵌套)
代码:
func animation_2(){
let lay = CAReplicatorLayer()
lay.bounds =CGRect(x:0, y:0, width:320, height:320)
lay.position =view.center
lay.backgroundColor =UIColor.clear.cgColor
// view.layer.addSublayer(lay)
let redSquare = CALayer()
redSquare.backgroundColor =UIColor.white.cgColor
redSquare.frame =CGRect(x:0, y:0, width:40, height:40)
let instanceCount = 5
lay.instanceCount = instanceCount
lay.instanceTransform =CATransform3DMakeTranslation(50,0,0)
let offsetStep = -1 / Float(instanceCount)
lay.instanceBlueOffset = offsetStep
lay.instanceGreenOffset = offsetStep
lay.addSublayer(redSquare)
let outerReplicatorLayer = CAReplicatorLayer()
outerReplicatorLayer.addSublayer(lay)
outerReplicatorLayer.instanceCount =instanceCount
outerReplicatorLayer.instanceTransform =CATransform3DMakeTranslation(0,50,0)
outerReplicatorLayer.instanceRedOffset =offsetStep
view.layer.addSublayer(outerReplicatorLayer)
}
case 3:(圆点旋转动画)
代码:
func animation_2() {
//创建CAReplicatorLayer对象
let lay = CAReplicatorLayer();
lay.bounds =CGRect(x:0, y:0, width:150, height:150)
lay.cornerRadius =10
lay.backgroundColor =UIColor(white:0.0, alpha:0.3).cgColor
lay.position =view.center
view.layer.addSublayer(lay)
//创建单个点
let dot = CALayer()
dot.bounds =CGRect(x:0, y:0, width:15, height:15)
dot.position =CGPoint(x:lay.frame.size.width/2,y:20)
dot.backgroundColor =UIColor(white:0.8, alpha:1.0).cgColor
dot.backgroundColor =UIColor.white.cgColor
dot.cornerRadius = dot.frame.size.width/2
lay.addSublayer(dot)
//
let dot_num:Int = 15
lay.instanceCount = dot_num
let dot_angle = CGFloat(2*Double.pi)/CGFloat(dot_num)
lay.instanceTransform =CATransform3DMakeRotation(dot_angle,0,0,1.0)
let duration:CFTimeInterval = 1.5
let scale_animation = CABasicAnimation(keyPath:"transform.scale")
scale_animation.fromValue =1.0
scale_animation.toValue =0.1
scale_animation.duration = duration
scale_animation.repeatCount =Float.infinity
dot.add(scale_animation, forKey:nil)
lay.instanceDelay = duration/Double(dot_num)
dot.transform =CATransform3DMakeScale(0.01,0.01,0.01)
}
case 4:
代码:
func animation_4(){
let lay = CAReplicatorLayer()
lay.bounds =CGRect(x:0, y:0, width:60, height:60)
lay.position =view.center
lay.backgroundColor =UIColor.clear.cgColor
view.layer.addSublayer(lay)
let bar = CALayer()
bar.bounds =CGRect(x:0, y:0, width:8.0, height:40.0)
bar.position =CGPoint(x:10, y:75)
bar.cornerRadius =2.0
bar.backgroundColor =UIColor.red.cgColor
lay.addSublayer(bar)
let move = CABasicAnimation(keyPath: "position.y")
move.toValue = bar.position.y -35.0
move.duration =0.5
move.autoreverses =true
move.repeatCount =Float.infinity
bar.add(move, forKey:nil)
lay.instanceCount =3
lay.instanceDelay =0.33
lay.masksToBounds =true//裁剪掉超出边缘部分
lay.instanceTransform =CATransform3DMakeTranslation(10.0,0,0)//平移
}
注:如需了解更多请看官方文档:https://developer.apple.com/documentation/quartzcore/careplicatorlayer?preferredLanguage=occ#
- CAReplicatorLayer的使用示例
- CAReplicatorLayer的使用
- IOS使用CAReplicatorLayer重建动态的倒影
- iOS使用CAReplicatorLayer重建动态的倒影
- ios CAReplicatorLayer使用
- CAReplicatorLayer
- CAReplicatorLayer
- 使用CAReplicatorLayer自定义简单指示器
- CALayer动画实践(二):CAReplicatorLayer的用法
- iOS quartzCore第六章—— CAReplicatorLayer的运用
- CAReplicatorLayer ReflectionView
- iOS CAReplicatorLayer简单笔记
- CAReplicatorLayer 学习和实践
- 用 CAReplicatorLayer 创建动画
- iOS 环绕动画 CAReplicatorLayer
- ios 音乐跳动动画-CAReplicatorLayer
- iOS开发之iOS中的动画实现,通过CAShapeLayer、CAShapeLayer,CAReplicatorLayer实现炫酷的动画、雷达效果,波纹效果,咻一咻效果。iOS核心动画实现。
- Core Animation实例2-活动指示器(CAReplicatorLayer复制层)
- 大型web系统数据缓存设计
- 设计模式(一)-策略模式
- servlet向客户端返回JSON数据
- 制作nginx+php的docker镜像方法
- Java中抽象类和接口中有构造方法吗?
- CAReplicatorLayer的使用
- Java实现-最小子串覆盖
- CentOS7安装mysql
- 用大白话聊聊分布式系统
- 一个好的PS笔刷(笔触)下载论坛
- python 读取并显示图片的两种方法
- SVN clean up失败或是lock等问题解决方案
- Qt基本图形绘制
- java的thsi关键字用法