IOS Animation Basics

Source: Internet
Author: User
<span id="Label3"> </p>Today to talk about the basics of animation, I hope to help some just contact iOS animation or just start learning iOS classmates, If there is objection, I hope to correct, thank You.   Some basic concepts       The following is what is covered under the Quartzcore Framework.      1, camediatimingfunction                time functions (also known as buffer functions), Used to describe the rate of motion during an animation, or as an acceleration, Apple offers four ways:                       &NBSP ;                            &NBSP;&NBSP;&NBSP;&N Bsp; kcamediatimingfunctionlinear                  Uniform                     kcamediatimingfunctioneasein     &NBS P            slow-in                      kcamediatimingfunctioneaseout                slow-out     & nbsp           &NBSP;   kcamediatimingfunctioneaseineaseout       slow-in/slow-out                     kcamediatimingfunctiondefault                 &NB Sp   By default                 Four scenarios can be used to represent:            &NB Sp                  of course, in addition to providing us with the way, we can also customize the time function, through the + functionwithcontrolpoints:::: Method.                 This approach is to pass in two points (control Point) (the first two are one, the last two are a point). The first point forms the first tangent to the origin, and the second point forms another tangent, such as the incoming point (1,0) and (0.75,1), and its rate (acceleration) corresponds to the graph:                                     ,         &NB Sp                                  &NBS P           So you can customize what you want toThe time function to Be.      2, camediatiming          This is a protocol that is respected by Calayer and caanimation, it is a tiered timing system, Describes the mapping of an object to the local time relative to the parent object (a bit around, This sentence should be translated, please God teach:the <code><code>CAMediaTiming</code></code>Protocol models a hierarchical timing system, with each object describing the mapping of time values from the object ' s par ent to local time.).     It is mainly used to describe the start, execution time, execution rate, number of repetitions, etc. in the Animation. 3, Cftimeinterval represents the time interval, is the double type, from the alias 4, catransaction document described in this way: "transactions is coreanimation batch processing layer -tree to the mechanism of the update rendering of atoms, each layer tree change needs to transaction this part. Coreanimation supports two transactions, "show" transaction and "implicit" Transaction. The transaction shown is called before changing the layer tree [catransaction begin], and then [catransaction commit]. The implicit transaction is that when a layer tree without an active transaction is modified in a thread, coreanimation automatically creates the transaction, These transactions are automatically committed in the next iteration of runloop, and in some special cases (E.G. no runloop or Runloop blocked), You must render the layer with the transaction at the right time The Tree's heel is NEW. "i believe the description in the document clearly explains what Catransaction is doing and how it works." Here is an example of a simple explanation in the example, first look at:<p><p></p></p>This is a simple modification layer of the properties of the formation of animation, a lot of properties of the layer is to support the implicit animation, you only need to modify his properties, it will automatically add an animation effect. The above effect, the code is as follows: very simple code, just click on the button to modify the Layer's position and Backgroundcolor. This belongs to the above mentioned implicit transaction, if you change to show animation is written like this, you may feel that the result of this writing is the same as the result above, there is no way to determine whether the animation is displayed, you You can remove the code from the commit line below, run it, and you will see that there is no animation, which is mentioned in the above document, and the commit is a series of transaction (transactions) commits, waiting for the next runloop to Render. You can also change the time of the animation by setting catransaction, and the camediatimingfunction of the previous learning, the code is as Follows:<p><p>Of course you can use the + (void) setanimationduration: (cftimeinterval) dur; method to set the animation time, the time function can Also.</p></p><p><p>Another way to turn off implicit animations is to set Disableaction to no, by setdisableactions: or kcatransactiondisableactions.</p></p>          Catransaction is also available in Setcompletionblock or kcatransactioncompletionblock, Using the above two methods can be set after the animation of the callback, this should still be very useful, a lot of animation after the need to do a certain action.      5, caaction          This is a protocol, defined in Calayer's header file, The Caanimation and Calayer classes have complied with this Agreement. It has a method that when an object occurs an event, it calls this method, the parameter is the name of the event, the object that occurs is anobject, and the parameters associated with this event are saved by Dic.             We all know that UIView is a package for calayer, UIView follows calayerdelegate, Implementation of the method of the Protocol (specific UIView and Calayer of the relationship and difference here is not too much to describe), there will be a question, why Calayer properties have implicit animation, and UIView layer does not?             We start with the Calayer method actionforkey: the method says that when we change the properties of calayer, this method is called to pass the property name:                    1 To determine whether the current delegate object implements the Actionforlayer:forkey: method, called if implemented; nbsp                   2, Check if there is a current attribute name in the actions dictionary for this layer                     3, Check the "style" level for the current property name in any of the actions dictionaries         &NBSP           4, If none of the above steps are found, then call the default Defaultactionforkey: method           & nbsp         Note: any of the above steps to return Non-nil action objects will be ignored (do Nothing)               so, we can customize A uiview, and then rewrite the parent Class's actionforlayer:forkey: method, return nil, You can let a uiview also have implicit animation, quickly try it.               How does the implicit animation actually happen? Let's go ahead and see what Calayer did, we give custom UIView custom a layer,layer that has the method of adding and removing animation in our custom Calayer rewrite addanimation:forkey: method, When you click the button and change the properties of the layer, the effect is as follows: from the result, the implicit animation is also animated for the current Layer.                 Let's do another experiment that just returns nil in the Actionforlayer:forkey method that was rewritten in the custom uiview, The effect of implicit animation on the layer of the custom view is Then:<p><p>It can be seen that the Actionforlayer method in the custom view has been called and added animations to the Layer. When you add judgment in the Actionforlayer:forkey: method:</p></p><p><p>In this way, the implicit animation of position is no more, only the animation of Backgroundcolor. It also confirms the 4 steps mentioned Above.</p></p>So much for today, and later to add ... (not finished, to be continued)<p><p>IOS Animation Basics</p></p></span>

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.