1

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.

2
  • add me to amir.ios. I want to see the actual code Commented Aug 8, 2014 at 6:38
  • Try calling [self setupCircle] and [self animateCircle] in ViewDidAppear instead of ViewDidLoad Commented Aug 8, 2014 at 6:39

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

You can try this code;

[self performSelector:@"setupCircle" withObject:nil afterDelay:0.1];
[self performSelector:@"animateCircle" withObject:nil afterDelay:0.1];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.