我有一个心形的uibezier路径,并且一直使用CAShapeLayers来屏蔽并使用bound.height的CABasicAnimation从底部填充红色。我显然得到了一些关键的混合,因为形状显示为充满红色,然后从底部清除!尔加!此动画由UILongPressGestureRecognizer触发,fyi。谁能告诉我在哪里搞砸了?这是代码:
var filledShape = CAShapeLayer()
filledShape.bounds = bezierPath.bounds
filledShape.path = bezierPath.CGPath
filledShape.fillColor = UIColor.redColor().CGColor
var outlineShape = CAShapeLayer()
outlineShape.path = CGPathCreateWithRect(bezierPath.bounds, nil)
outlineShape.anchorPoint=CGPointMake(0.5, 1.0)
outlineShape.lineWidth = 1.5
var inPlaceOutlineShape = CAShapeLayer()
inPlaceOutlineShape.bounds = filledShape.bounds
inPlaceOutlineShape.path = filledShape.path
inPlaceOutlineShape.fillColor = UIColor.clearColor().CGColor
inPlaceOutlineShape.strokeColor = UIColor.redColor().CGColor
inPlaceOutlineShape.opaque=false
inPlaceOutlineShape.lineWidth = 1.5
filledShape.mask=outlineShape
var heartRect = CGRectMake(self.view.center.x,self.view.center.y, bezbox.width+1, bezbox.height+1)
var animateOutlineFromBottom = CABasicAnimation(keyPath: "bounds.size.height")
animateOutlineFromBottom.fromValue=0
animateOutlineFromBottom.toValue=bezbox.height
animateOutlineFromBottom.duration=3.0
animateOutlineFromBottom.fillMode=kCAFillModeForwards
//animateOutlineFromBottom.
bgview.frame = heartRect
bgview.layer.addSublayer(filledShape)
bgview.layer.addSublayer(inPlaceOutlineShape)
self.view.addSubview(bgview)
outlineShape.addAnimation(animateOutlineFromBottom, forKey:"bounds.size.height")
提前致谢!!
答案 0 :(得分:2)
您将蒙版的动画从0设置为有限高度。而是将面具的位置从底部位置更改为顶部位置。
var animateOutlineFromBottom = CABasicAnimation(keyPath: "position")
animateOutlineFromBottom.fromValue = NSValue(CGPoint: CGPointMake(0, heartRect.height))
animateOutlineFromBottom.toValue = NSValue(CGPoint: CGPointMake(0,0))
animateOutlineFromBottom.duration = 3.0
animateOutlineFromBottom.fillMode = kCAFillModeForwards
// Other code
outlineShape.addAnimation(animateOutlineFromBottom, forKey:"position")