views:

23

answers:

1

My iPhone app has two main "views": a UIViewController with some buttons, text etc and a window where all the OpenGL ES stuff happens. When I transition from the UIViewController to the window (when the user clicks "play" for example) I just do:

[window ExchangeSubviewAtIndex:0 withSubviewAtIndex:1];

Perhaps this is not the ideal way to do this? I don't want to deallocate the resources used by the UIViewController... I just want the window to be in front. How can I animate the transition from the UIViewController to the window?

I'm really looking for a very simple fade-to-black animation.

+2  A: 

Have you tried plain old UIViewAnimation clause? Maybe play with view properties of hidden or alpha and if you want this to fade out to black, you need to [Window setBackgroundColor:[UIColor blackColor]]; first. Make sure the animations happen in the main thread. Sample code following with view1 being the first subview of window and view2 the other subview of window.

- (void)switchToView1 {
[UIView beginAnimations:@"fadeOut1" context:NULL];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
view1.hidden = YES;
[UIView commitAnimations];  
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void    *)context {
if ([@"fadeOut1" isEqualToString:animationID] && [finished intValue] == 1) {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.5];
    view2.hidden = NO;
    [UIView commitAnimations];
}
}

Tell me if this works, good luck.

tsakoyan
Thanks for the response! I got something similar to work: set the viewController.view.hidden = YES... then draw black over the opengl surface... then fade in the opengl surface. So I guess I did the animation manually instead of using the UIView animation stuff.
MrDatabase
Happy to be of help, but did you get the fade out effect on the UIViewController's view this way?
tsakoyan