How to do the flip animation between two UIViewControllers while clicking info button?

Rajkanth picture Rajkanth · Jan 7, 2011 · Viewed 53.9k times · Source

I have a login page named "LoginViewController". I have an info button in this page. If I click on it, I want to show some information about my application. Also I want to present that information page using flip animation.

The code for creating info button is,

infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(285, 425, 30, 30);
infoButton.backgroundColor = [UIColor clearColor];

[infoButton addTarget:self 
            action:@selector(displayInfoView) 
            forControlEvents:UIControlEventTouchUpInside];

If I click on the info button, the displayInfoView method will be called. There I can show a UIView to display some information. Am I right?

For flip animation, I used this code...

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:.8];

[UIView setAnimationTransition:([loginPageView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) 
        forView:mainView
        cache:YES]; 

if ([infoView superview]) {
    [infoView removeFromSuperview];
    [mainView addSubview:loginPageView];
}
else {
    [loginPageView removeFromSuperview];
    [mainView addSubview:infoView];
}

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];

Here loginPageView is the login view that contains the info button. infoView is the view that contains the information about application. mainView is the common view that holds the present view.

Now my problem is, instead of showing a UIView, can I show an another view controller class while clicking the info button? Remember the flip action works fine with UIView. But when I try with a UIViewController, this makes trouble.

Can someone suggest me how to show an UIViewController ( in my app, I need to show AboutViewController) while clicking the info button with the flip effect?

Answer

Filip Radelic picture Filip Radelic · Sep 12, 2011

To flip into a view controller:

viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:viewController animated:YES completion:nil];

To flip out of it:

[self dismissViewControllerAnimated:YES completion:nil];