Application of uiview layer animation in view Conversion

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.