Imagine a CAGradientLayer.
It's very easy to animate .startPoint and .endPoint.
Now imagine a float spinLike which simply sets both of them at once.
{So, instead of having two different animations, you could simply animate spinLike.}
So something like ..
class CustomGradientLayer: CAGradientLayer {
@objc var spinLike: CGFloat = 0 {
didSet {
startPoint = CGPoint( ... )
endPoint = CGPoint( ... )
setNeedsDisplay()
}
}
}
To animate spinLike...
class Test: UIView {
...
g = CustomGradientLayer()
a = CABasicAnimation(keyPath: "spinLike")
...
g.add(a, forKey: nil)
...
But.
It doesn't work, startPoint and endPoint are not moved at all.
What is wrong?
Note - tragically it seems you can not @NSManaged a property which has a didSet...
Note - it's easy enough to make your own custom animation by just overriding the draw loop.
There are many examples of this around. This is how you do it:
class CircleProgressLayer: CALayer {
@NSManaged var progress: CGFloat
override class func needsDisplayForKey(key: String) -> Bool {
if key == "progress" {
return true
}
return super.needsDisplayForKey(key)
}
override func draw(in ctx: CGContext) {
path.fill() etc etc... your usual drawing code
}
}
Unfortunately my question here is
Unrelated to actual drawing:
By animating the property spinLike,
I simply want to change each frame existing ordinary animatable properties (in the example, .startPoint and .endPoint )
How do you do this?
Note! You can't change .startPoint and .endPoint in drawInContext - you'd be attempting to modify read-only layer
