CABasicAnimation在swift 3中不起作用

时间:2016-10-13 03:35:19

标签: ios swift swift3 cabasicanimation

   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

请帮忙,

0 个答案:

没有答案