CALayer의 경계를 애니메이션화하려고하는데 작동하지 않습니다. 여기 코드는 : 나는 initWithFrame
방법에서 사라 호출하면CALayer 불투명도 애니메이션이 작동하지만 경계 애니메이션이 적용되지 않습니다.
class CircleView < UIIVew
def initWithFrame(frame)
super
# determine the dimensions
radius = (bounds.size.width < bounds.size.height ? bounds.size.width : bounds.size.height)/2
# create the circle layer
@circle = CAShapeLayer.layer
@circle.bounds = bounds
@circle.path = UIBezierPath.bezierPathWithRoundedRect(bounds, cornerRadius: radius).CGPath
@circle.fillColor = UIColor.blueColor.CGColor
# add the circle to the view
self.layer.addSublayer(@circle)
shrink
self
end
private
# Applies the shrink animation to the provided circle layer.
def shrink
# determine the bounds
old_bounds = @circle.bounds
new_bounds = CGRectMake(old_bounds.size.width/2, old_bounds.size.height/2, 0, 0)
# animate the shrinking
animation = CABasicAnimation.animationWithKeyPath("bounds")
animation.fromValue = NSValue.valueWithCGRect(old_bounds)
animation.toValue = NSValue.valueWithCGRect(new_bounds)
animation.duration = 3.0
@circle.addAnimation(animation, forKey:"bounds")
# set the bounds so the animation doesn't bounce back when it's complete
@circle.bounds = new_bounds
end
# Applies the shrink animation to the provided circle layer.
def disappear
# animate the shirnk
animation = CABasicAnimation.animationWithKeyPath("opacity")
animation.fromValue = NSNumber.numberWithFloat(1.0)
animation.toValue = NSNumber.numberWithFloat(0.0)
animation.duration = 3.0
@circle.addAnimation(animation, forKey:"opacity")
# set the value so the animation doesn't bound back when it's completed
@circle.opacity = 0.0
end
end
는 애니메이션이 잘 작동합니다. 그러나 shrink를 호출하면 아무 일도 일어나지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
완벽하게 작동했습니다! 도와 주셔서 감사합니다! 경계 애니메이션을 나갈 수있었습니다. – LandonSchropp