MrDatabase
MrDatabase

Reputation: 44505

Animated transition between UIViewController and EAGLView

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.

Upvotes: 0

Views: 1619

Answers (1)

tsakoyan
tsakoyan

Reputation: 1891

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.

Upvotes: 2

Related Questions