1

I'm using CABasicAnimation to animate from path to another.

I've created a mask view in this way:

 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)
     }

}

Calling animate function with same shape there are no problems. Else calling animate with different hole shapes, I obtain strange behaviour on animation (gif)

Any advice?

enter image description here

Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146

0 Answers0