I have a subclass UIViewthat shows a circular move:

The screenshot shows the progress with the value 0.667.
Inside my subclasses UIViewin the method, drawRect:I draw two circles: one for the background oval (gray), the second for the actual oval move (blue). (Check source code)
It works as expected, but does not allow you to animate progress changes. I tried to find a solution that allows using the class method UIView animateWithDuration:animations:as follows:
MyCustomView *progressView = ...
[UIView animateWithDuration:3
animations:^{
progressView.progressValue = 1.f;
}];
But I could not make it come to life.
You can check the source code of my GitHub repository .
, , progressValue . , ( UIView animateWithDuration:animations:), , . CALayer UIView. , , custom_layer. CALayer .
: UIView, (progressValue), UIView animateWithDuration:animations: (progressValue)?
UPDATE
rounak answer drawRect: CAShapeLayer s. , progressValue, strokeEnd , , , ( ).
actionForLayer:forKey: ( ), CABasicAnimation, strokeEnd, progressValue .
, :
__block NSDate *date = [NSDate date];
[UIView animateWithDuration:3
animations:^{
self.progressView.progressValue = 1.f;
}
completion:^(BOOL finished1) {
NSLog(@"first animation completed in %f", [[NSDate date] timeIntervalSinceDate:date]);
date = [NSDate date];
[UIView animateWithDuration:3
animations:^{
self.progressView.progressValue = 0.f;
}
completion:^(BOOL finished2) {
NSLog(@"second animation completed in %f", [[NSDate date] timeIntervalSinceDate:date]);
[self animateProgress];
}];
}];
progressValue, , 3 . , ( ). :

, , , [CABasicAnimation animationWithKeyPath:@"strokeEnd"] strokeEnd ( ).
, , .
2
, setProgressValue: setter:
self.progressOvalLayer.strokeEnd = MIN(1, MAX(0, progressValue));
self.backgroundOvalLayer.strokeEnd = MIN(1, MAX(0, 1 - progressValue));
(. GitHub)
, actionForLayer:forKey: , ( brakepoint).
, ?
-
, UIView , . actionForLayer:(CALayer *)layer forKey:, ( ). .