let path = CGMutablePath()
path.move(to: CGPoint(x:0.0, y:10.5))
path.addLine(to: CGPoint(x: (self.frame.width/2), y:20.5))
let pathInit = CGMutablePath()
pathInit.move(to: CGPoint(x: 0, y:0))
pathInit.addLine(to: CGPoint(x: self.frame.width/2, y: 0))
// update the path property on the mask layer, using a CATransaction to prevent an implicit animation
let mask = CAShapeLayer()
mask.path = pathInit
let maskLayer: CAShapeLayer = CAShapeLayer()
maskLayer.path = pathInit
self.layer.mask = maskLayer
let anim = CABasicAnimation(keyPath: "path")
anim.fromValue = maskLayer.path
anim.toValue = path
anim.duration = 0.25
anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
maskLayer.add(anim, forKey: nil)
CATransaction.begin()
CATransaction.setDisableActions(true)
maskLayer.path = path
CATransaction.commit()
我迁移到swift 3后这个函数不起作用,我认为是因为CABasicAnimation或CGMutablePath
请帮忙,