Every iOS app has a uiwindow instance. This is just a subclass of uiview. Therefore, we can make animations on uiwindow, and such animations can be used to convert views.
The following project is created using xcode4.2
1. Create an empty application and set it as follows:
2. Add a viewcontroller class and configure it as follows:
Open FVC. XIB, add a button, name it goto two, and add a response function for its touch up inside Event.
3. Use the same method above to add an SVC class, a button, and a response function for its touch up inside Event.
4. Modify the appdelegate. h file as follows:
@ Classfvc;
@ Classsvc;
@ Interface appdelegate: uiresponder <uiapplicationdelegate> {
FVC * _ FVC;
SVC * _ SVC;
}
@ Property (strong, nonatomic)
Uiwindow * window;
-(Void) flipaction :( ID) sender;
@ End
5. Implement the flipaction function in appdelegate. M:
# Pragma mark-
# Pragma mark = flip action =
# Pragma mark-
-(Void) flipaction :( ID) sender {
[Uiviewbeginanimations: nilcontext: NULL];
[Uiviewsetanimationduration: 0.5];
[Uiviewsetanimationtransition :( [_ FVC. viewsuperview]
? Uiviewanimationtransitionflipfromleft: uiviewanimationtransitionflipfromright)
Forview: Self. windowcache: Yes];
If ([_ FVC. viewsuperview]) {
[_ FVC. viewremovefromsuperview];
[Self. windowaddsubview: _ SVC. View];
} Else {
[_ SVC. viewremovefromsuperview];
[Self. windowaddsubview: _ FVC. View];
}
[Uiviewcommitanimations];
}
6. Modify the function in appdelegate. M.
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
_ SVC = [[svcalloc]
Initwithnibname: @ "SVC" Bundle: Nil];
_ FVC = [[fvcalloc]
Initwithnibname: @ "FVC" Bundle: Nil];
Self. Window = [[uiappswalloc]
Initwithframe: [[uiscreenmainscreen]
Bounds] autorelease];
// Override point for customization after application launch.
Self. Window. backgroundcolor
= [Uicolorwhitecolor];
[Self. windowaddsubview: _ FVC. View];
[Self. windowmakekeyandvisible];
Return
Yes;
}
7. Modify the dealloc function in appdelegate. M.
-(Void) dealloc
{
[_ Svcrelease];
[_ Fvcrelease];
[_ Windowrelease];
[Superdealloc];
}
Never forget the memory management.
8. Implement the response Event code of the button in FVC. M:
# Import "appdelegate. H"
-(Ibaction) gototwo :( ID) sender {
Appdelegate * appd = (appdelegate *) [uiapplicationsharedapplication]. Delegate;
[Appd flipaction: Nil];
}
9. Do the same thing in SVC. M.
The project code is as follows:
Http://download.csdn.net/detail/NickTang/3692498