In viewDidAppear
I call the following code:
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
myView.backgroundColor = [UIColor clearColor];
[self.view addSubview:myView];
[myView setProgress:0.3 animated:YES];
That last line calls this method:
- (void)setProgress:(CGFloat)progress animated:(BOOL)animated {
self.innerPie.hidden = NO;
self.innerPie.strokeEnd = progress;
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
pathAnimation.duration = 3.0;
pathAnimation.fromValue = [NSNumber numberWithFloat:self.progress];
pathAnimation.toValue = [NSNumber numberWithFloat:progress];
[self.innerPie addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
self.progress = progress;
}
Yet the animation never starts when I load the simulator. Why? Has the view not already appeared, as indicated?
Oddly enough, if I use dispatch_after
with a 0 second delay (instant) it will show.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[myView setProgress:0.8 animated:YES];
});
What am I doing wrong?