CABasicAnimation เพื่อกำหนดเส้นทางพฤติกรรมแปลก ๆ [ซ้ำกัน]

ฉันใช้ 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)

คำแนะนำใด ๆ?

ป้อนคำอธิบายรูปภาพที่นี่


person Luca Davanzo    schedule 18.10.2016    source แหล่งที่มา