0

i want to create a custom animation for the animation of the pushViewController using a sequence of images.

I have done this up to the point the the currentViewController is covered with the images i want but i don't know if i's possible to reveal the nextViewController when trying to reverse the order of the animation images.

so far i have the following

- (IBAction)nextAction:(id)sender {

    UIImage* img1 = [UIImage imageNamed:@"image-1.png"]; 
    UIImage* img2 = [UIImage imageNamed:@"image-2.png"];
    UIImage* img3 = [UIImage imageNamed:@"image-3.png"];
    UIImage* img4 = [UIImage imageNamed:@"image-4.png"];
    UIImage* img5 = [UIImage imageNamed:@"image-5.png"];

    NSArray *animationImages = [NSArray arrayWithObjects:img1,img2,img3,img4,img5,nil];

    CALayer *myLayer = [CALayer layer];
    myLayer.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);
    myLayer.position =  self.view.center; //CGPointMake(0.0 ,0.0);
    CAKeyframeAnimation *animationSequence = [CAKeyframeAnimation animationWithKeyPath: @"contents"];
    animationSequence.calculationMode = kCAAnimationLinear;
    animationSequence.autoreverses = NO;
    animationSequence.duration = 0.4;
    animationSequence.delegate = self;
    animationSequence.repeatCount = 1; //HUGE_VALF;
    NSMutableArray *animationSequenceArray = [[NSMutableArray alloc] init];
    for (UIImage *image in animationImages) 
    {
        [animationSequenceArray addObject:(id)image.CGImage];
    }
    animationSequence.values = animationSequenceArray;
    [myLayer addAnimation:animationSequence forKey:@"contents"];    
    [self.view.layer addSublayer:myLayer];

}


- (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished {

    NextViewController *nextViewController;
    nextViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
    nextViewController.title = @"next";

    [self.navigationController pushViewController:nextViewController animated:NO];
    [nextViewController release];

}

the IBAction nextAction is executed when the user presses a button and the images get animated on top of the current view.

What i want to achieve is after the images are on top, push the nextViewController under the images and reverse the animation so the nextViewController gets revealed.

I hope this makes sense. It's just like having a photo, placing a number of cards on top of the photo and then removing the cards revealing a different photo.

Teo

Matthias Bauch
  • 89,811
  • 20
  • 225
  • 247
teo
  • 269
  • 1
  • 5
  • 11

1 Answers1

0

Instead of adding that animated layer onto the current viewController, add that layer directly onto the current keyWindow. That will hide your current viewController.

[[[UIApplication sharedApplication] keyWindow] layer addSublayer:myLayer];

Once the first half of your animation is done (or in other words, once the complete animation in forward order is done), remove the animation layer. replace the viewController with that new one and add the second animation layer again onto the keyWindow - now start the second half of your animation. Once that is done, remove the animation layer from the keyWindow.

Depending on the structure of your application, you could also use a rootViewController that effectively resides below your additional viewControllers as the superview/superlayer of your animation layer.

[[[[UIApplication sharedApplication] rootViewController] view] layer addSublayer:myLayer];
Till
  • 27,559
  • 13
  • 88
  • 122
  • I'm trying to use [[[UIApplication sharedApplication] keyWindow].layer addSublayer:myLayer]; but is there a way to now when the animation is half way in order to push the nextViewController; – teo May 19 '12 at 09:05
  • I was assuming that the first half of your entire presentation animation actually was a complete animation as posted above. – Till May 19 '12 at 09:08