CABasicAnimation路径奇怪的行为

时间:2016-10-18 08:44:17

标签: ios objective-c swift animation uibezierpath

我使用CABasicAnimation从路径动画到另一个。

我已经用这种方式创建了一个蒙版视图:

 class Mask: UIView {

     func setup() {
       self.path = UIBezierPath(roundedRect: CGRectMake(0.0, 0.0, self.frame.width, self.frame.height), cornerRadius: 0.0)
       self.path.usesEvenOddFillRule = true
       self.fillLayer.fillColor = self.color.CGColor
       self.fillLayer.opacity = self.opacity
       self.fillLayer.fillRule = kCAFillRuleEvenOdd
       self.layer.addSublayer(self.fillLayer)
       self.holePath = self.getHolePath(frame: frame, center: center, shape: shape, diameter: diameter)
       self.path.appendPath(self.holePath)
       self.fillLayer.path = self.path.CGPath
     }

     func animate() {
       let animation = CABasicAnimation(keyPath: "path")
       animation.duration = duration
       animation.fromValue = self.path.CGPath
       animation.toValue = self.nextPath()
       animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
       animation.fillMode = kCAFillModeForwards
       animation.removedOnCompletion = false
       self.fillLayer.addAnimation(animation, forKey: nil)
     }

}

调用具有相同形状的animate函数没有问题。否则使用不同的孔形状调用animate,我会在动画(gif)上获得奇怪的行为

有什么建议吗?

enter image description here

0 个答案:

没有答案