Handling inactive status for iOS development (105)

Source: Internet
Author: User
1 Preface

ApplicationProgramThe simplest status is to transition from activity to activity, and then return to activity. Today, let's use an example to look at its specific application.

2. Details

The content here is relatively simple.CodeNow

 

Zyviewcontroller. m

 

/// Zyviewcontroller. M // state lab /// created by zhangyuc on 13-6-8. // copyright (c) 2013 zhangyuc. all rights reserved. // # import "zyviewcontroller. H "@ interface zyviewcontroller () @ end @ implementation zyviewcontroller @ synthesize label; @ synthesize animate;-(void) viewdidload {[Super viewdidload]; // register the notification [[nsnotificationcenter defacenter center] addobserver: Self selector: @ selector (applicationwillresign Active :) name: jsonobject: [uiapplication sharedapplication]; [[nsicationcenter center defacenter center] addobserver: Self selector: @ selector (applicationdidbecomeactive :) name: jsonobject: [uiapplication sharedapplication]; cgrect bounds = self. view. bounds; cgrect labelframe = cgrectmake (bounds. origin. x, cgrectgetmidy (bounds)-50, Bo UNDS. size. width, 100); self. label = [[uilabel alloc] initwithframe: labelframe]; label. font = [uifont fontwithname: @ "Helvetica" Size: 70]; label. TEXT = @ "Archy! "; Label. textalignment = uitextalignmentcenter; label. backgroundcolor = [uicolor clearcolor]; [self. view addsubview: Label]; // [self rotatelabeldown];}-(void) didreceivememorywarning {[Super didreceivememorywarning]; // dispose of any resources that can be recreated .} -(void) dealloc {[label release]; [Super dealloc];}-(void) rotatelabeldown {// implicit animation, core animation will smoothly transition the attribute from its current value to the value we set. After that, you can perform any operations. [Uiview animatewithduration: 0.5 animations: ^ {// set the specific rotation angle for the label's transform (in radians ). Label. transform = cgaffinetransformmakerotation (m_pi);} // They also set a program block to call other methods, so that the text repeatedly displays the animation completion: ^ (bool finished) {[self rotatelabelup];}-(void) rotatelabelup {[uiview animatewithduration: 0.5 animations: ^ {label. transform = cgaffinetransformmakerotation (0);} completion: ^ (bool finished) {// Add judgment condition if (animate) [self rotatelabeldown] ;}];}-(void) applicationwillresignactive :( uiapplication *) Application {nslog (@ "% @", nsstringfromselector (_ cmd); animate = no;}-(void) applicationdidbecomeactive :( uiapplication *) application {nslog (@ "% @", nsstringfromselector (_ cmd); animate = yes; [self rotatelabeldown];} @ end

 

Running result


Console result:

 

13:20:24. 265 state lab [414: c07] Application: didfinishlaunchingwitexceptions:

13:20:24. 287 state lab [414: c07] applicationdidbecomeactive:

13:20:24. 288 State Lab [414: c07] applicationdidbecomeactive:

Press the Home button to view the console result:

 

13:21:57. 394 state lab [414: c07] applicationwillresignactive:

13:21:57. 395 state lab [414: c07] applicationwillresignactive:

13:21:57. 396 state lab [414: c07] applicationdidenterbackground:

Result of the next app running:


Console result

 

13:22:44. 051 state lab [414: c07] applicationwillenterforeground:

13:22:44. 052 state lab [414: c07] applicationdidbecomeactive:

13:22:44. 053 state lab [414: c07] applicationdidbecomeactive:

3 conclusion

The above is all content and I hope it will help you.

Demo: http://download.csdn.net/detail/u010013695/5545277

 

Related Article

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.