原帖:http://www.jianshu.com/p/76c588893b19
-----------------------------------------------------------------------------------------------------------------------
主要代码:
let r =CAReplicatorLayer()
r.bounds =CGRectMake(0,0, 200,200)
r.cornerRadius =10
r.backgroundColor =UIColor(white: 0, alpha:0.75).CGColor
r.position =self.view.center
self.view.layer.addSublayer(r)
let dot =CALayer()
dot.bounds =CGRectMake(0,0, 14,14)
dot.position =CGPointMake(100,40)
dot.backgroundColor =UIColor(white: 0.8, alpha:1.0).CGColor
dot.borderColor =UIColor(white: 1.0, alpha:1.0).CGColor
dot.borderWidth =1.0
dot.cornerRadius =2.0
r.addSublayer(dot)
let nrDots:Int = 15
//复制次数
r.instanceCount = nrDots
let angle =CGFloat(2 *M_PI) / CGFloat(nrDots)
//复制内容相对位置
r.instanceTransform =CATransform3DMakeRotation(angle, 0, 0,1)
//缩放动画
let duration:CFTimeInterval = 1.5
let shrink =CABasicAnimation(keyPath: "transform.scale")
shrink.fromValue =1.0
shrink.toValue =0.1
shrink.duration = duration
shrink.repeatCount =Float.infinity
dot.addAnimation(shrink, forKey:nil)
r.instanceDelay = duration/Double(nrDots)
//修复第一次的缩放的bug
dot.transform =CATransform3DMakeScale(0.01,0.01, 0.01)
----------------水波纹理效果-----------------
let mainLayer = CAReplicatorLayer()
mainLayer.bounds = view.bounds
mainLayer.backgroundColor = UIColor.lightGrayColor().CGColor
mainLayer.position = view.center
view.layer.addSublayer(mainLayer)
let circleLayer = CAShapeLayer()
circleLayer.strokeColor = UIColor.whiteColor().CGColor
circleLayer.fillColor = UIColor.clearColor().CGColor
mainLayer.addSublayer(circleLayer)
circleLayer.frame = mainLayer.bounds
let x = (CGRectGetWidth(self.view.frame) - 50) / 2
let y = (CGRectGetHeight(self.view.frame) - 50) / 2
let fromRect = CGRectMake(x, y, 50, 50)
let toRect = CGRectMake(x - 175, y - 175, 400, 400)
let shaper = CAShapeLayer()
shaper.path = UIBezierPath.init(ovalInRect: fromRect).CGPath
shaper.strokeColor = UIColor.redColor().CGColor
shaper.fillColor = UIColor.redColor().CGColor
let zoomAnimation = CABasicAnimation.init(keyPath: "path")
zoomAnimation.duration = 3
zoomAnimation.fromValue = shaper.path
zoomAnimation.toValue = UIBezierPath.init(ovalInRect: toRect).CGPath
zoomAnimation.repeatCount = Float.infinity
zoomAnimation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)
circleLayer.addAnimation(zoomAnimation, forKey: "zoom")
let colorAnimation = CABasicAnimation.init(keyPath: "strokeColor")
colorAnimation.duration = 3
colorAnimation.fromValue = UIColor.redColor().CGColor
colorAnimation.toValue = UIColor.clearColor().CGColor
colorAnimation.repeatCount = Float.infinity
colorAnimation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)
circleLayer.addAnimation(colorAnimation, forKey: "fade")
mainLayer.instanceCount = 6
mainLayer.instanceDelay = 0.5