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?
This is how I'm doing it:
Credit goes to faysar here.
simple lines of code
To flip into a view controller:
To flip out of it:
There is a fundamental flaw in your understanding of the MVC structure in Cocoa Touch, which is, View Controllers and Views are comparable and similar. The truth is, they are Not.
Back to your specific question, yes, animations are based on views, not on view controllers. But each view should be controlled by one of your view controllers. And this which-view-belongs-to-which-controller thing is totally up to you. In your case, animation could happen between 2 views with 2 different controllers, or, they could also happen between 2 views of the same controller.
As for code samples, I suggest you take a look at one of Xcode's default templates, the Utility Application, which has implemented this click-and-flip animation in a succinct and standardized way.