Reputation: 193
I have some Core Animation code that works perfectly on a root View Controller (VC1), but when I change the root to another View Controller (VC2) that segues to VC1, the animations on VC1 never runs, even though its animation methods are called. Interestingly, if I turn off animate on the segue, the core animation on VC1 works.
This is my implementation of VC1:
CAShapeLayer* circleLayer;
- (void)setupCircle
{
CGPathRef circlePath = CGPathCreateWithEllipseInRect(CGRectMake(10, 40, 100, 100), nil);
circleLayer = [CAShapeLayer layer];
circleLayer.path = circlePath;
circleLayer.fillColor = [UIColor orangeColor].CGColor;
circleLayer.strokeColor = [UIColor blueColor].CGColor;
circleLayer.lineWidth = 10;
[self.view.layer addSublayer:circleLayer];
}
- (void)animateCircle
{
CABasicAnimation* circleAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
circleAnimation.duration = 4;
circleAnimation.fromValue = @0;
circleAnimation.toValue = @1;
[circleLayer addAnimation:circleAnimation forKey:@"circleAnimation"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupCircle];
[self animateCircle];
}
What is the problem? Thanks.
Upvotes: 1
Views: 474
Reputation: 1257
You can try this code;
[self performSelector:@"setupCircle" withObject:nil afterDelay:0.1];
[self performSelector:@"animateCircle" withObject:nil afterDelay:0.1];
Upvotes: 0
Reputation: 15335
but when I change the root to another View Controller (VC2) that segues to VC1
The problem in your cycle is viewDidLoad
, it doesn't get called if you back from the Child VC.
Put the stuff in the viewWillAppear
OR viewDidAppear
Upvotes: 1