iOS Animation core Animation

Source: Internet
Author: User
<span id="Label3"></p><p><p>Article Reprint: http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html</p></p><p><p>The main techniques for animating in iOS are: Core Animation.</p></p><p><p>The Core animation is responsible for all scrolling, rotating, zooming, and zooming, as well as all iOS animation effects. The Uikit class typically has a animated: parameter section, which allows you to use Animations.</p></p><p><p>Core animation is mainly used</p></p><p><p>We know that each uiview is associated with a calayer object, and Calayer is a layer in the core Animation.</p></p><p><p>The core animation is mainly to modify the layer to change the size of the ui, position, so as to achieve animation Effect.</p></p><p><p></p></p><p><p>It can be said that any application is inseparable from animation!</p></p><p><p>Even the switching operation in Apple's various UI controls has its intrinsic animation.</p></p><p><p></p></p><p><p>Learn some about Animation.</p></p><p><p></p></p><p><p>Any knowledge point, will move out a series of knowledge points.</p></p><p><p></p></p><p><p>[UIView beginanimations:@ "dropdownloadlabel" Context:uigraphicsgetcurrentcontext ()];</p></p><p><p>[UIView setanimationduration:0.5];</p></p><p><p>[UIView setanimationbeginsfromcurrentstate:no];</p></p><p><p></p></p><p><p>The animated code that executes</p></p><p><p></p></p><p><p>[UIView commitanimations];</p></p><p><p></p></p><p><p>Take this code as a starting point for knowledge and get to know it.</p></p><p><p></p></p><p><p>[UIView beginanimations:@ "dropdownloadlabel" Context:uigraphicsgetcurrentcontext ()];</p></p><p><p>[UIView commitanimations];</p></p><p><p></p></p><p><p>These two lines of code mark the beginning and end of an Animation. In the middle we can write some of our animation operations!</p></p><p><p></p></p><p><p><strong>beginanimations</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) beginanimations: (nsstring *) animationid context: (void *) Context</p></p><p><p>Used to represent the beginning of an Animation.</p></p><p><p>Animationid: as an identifier for an animation</p></p><p><p>Context: Custom Animation data that will be sent to the Animation's proxy method: setanimationwillstartselector: method and Setanimationdidstopselector: Method.</p></p><p><p>this, parameter, is usually Nil. We can set it directly to Nil.</p></p><p><p>here, we use Uigraphicsgetcurrentcontext (), because this method also returns nil by Default.</p></p><p><p></p></p><p><p>The method tells the system that we will start the Animation. and, after this method, we can set some parameters of the animation we make by Setanimationxxx (a series of methods).</p></p><p><p>After the animation is finished, call the Commitanimations method to notify the system that the animation ENDS.</p></p><p><p></p></p><p><p>At this point, we know that the method of setting some of the Animation's column parameters is the setanimationxxx method.</p></p><p><p></p></p><p><p>[UIView setanimationduration:0.5];</p></p><p><p>[UIView setanimationbeginsfromcurrentstate:no];</p></p><p><p></p></p><p><p>Animations can be Nested.</p></p><p><p></p></p><p><p>[UIView beginanimations:@ "animation_1" Context:uigraphicsgetcurrentcontext ()];</p></p><p><p>Code1</p></p><p><p>[UIView beginanimations:@ "animation_2" Context:uigraphicsgetcurrentcontext ()];</p></p><p><p>Code2</p></p><p><p>[UIView commitanimations];</p></p><p><p></p></p><p><p>[UIView commitanimations];</p></p><p><p></p></p><p><p></p></p><p><p>If we set up for animation, setanimationwillstartselector: method and Setanimationdidstopselector: Method.</p></p><p><p>Then when the animation starts or stops, the Animationid parameters and the context parameters of the animation are passed to the Setanimationwillstartselector: method and Setanimationdidstopselector: Method.</p></p><p><p></p></p><p><p></p></p><p><p>Tragedy is always going to happen!</p></p><p><p>The Apple API in its final description gives the following sentence:</p></p><p><p></p></p><p><p>Use of the This method was discouraged in IOS 4.0 and Later. You should use the Block-based animation methods to specify your animations Instead.</p></p><p><p>visible, after iOS 4.0, block syntax, greatly increased. This approach is not recommended and requires the way we use BLOCK.</p></p><p><p></p></p><p><p>so, The block way of Animation:</p></p><p><p></p></p><p><p>[UIView animatewithduration:0.3f delay:0.0f Options:uiviewanimationoptioncurvelinear</p></p><p><p>Animations:^{//execution of the animation code}</p></p><p><p>completion:^ (BOOL Finished) {</p></p><p><p>Execute code after completion</p></p><p><p>}];</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>Try to use block to complete the animation, because maybe when the old animation mode, will be Abolished.</p></p><p><p></p></p><p><p>By this, you can come to an adjourned. however, I would like this simple animation code, a look to the end!</p></p><p><p></p></p><p><p></p></p><p><p><strong>commitanimations</strong> <strong>method:</strong></p></p><p><p>+ (void) Commitanimations</p></p><p><p></p></p><p><p>Marks the end of the Animation. Paired with the Beginanimations Method.</p></p><p><p>For example:</p></p><p><p>[UIView commitanimations];</p></p><p><p></p></p><p><p><strong>A series of setanimationxxx methods:</strong></p></p><p><p></p></p><p><p><strong>setanimationduration</strong> <strong>method:</strong></p></p><p><p></p></p><p><p>+ (void) setanimationduration: (nstimeinterval) duration</p></p><p><p></p></p><p><p>Set Animation duration (seconds)</p></p><p><p></p></p><p><p>For example:</p></p><p><p>[UIView setanimationduration:0.5];</p></p><p><p></p></p><p><p></p></p><p><p><strong>setanimationbeginsfromcurrentstate</strong> <strong>Method</strong></p></p><p><p>+ (void) setanimationbeginsfromcurrentstate: (BOOL) fromcurrentstate</p></p><p><p></p></p><p><p>Sets the state at which the animation Starts.</p></p><p><p></p></p><p><p>We envision a scene: in general, we press a button and the animation will be executed Once.</p></p><p><p></p></p><p><p>When Yes: when the previous animation is executing, the current state of the previous animation will be the start of the next animation when the next animation starts.</p></p><p><p>When No: when the previous animation is in progress, when the next animation starts, the previous animation needs to revert to the completed state before the next animation Starts.</p></p><p><p></p></p><p><p><strong>setanimationstartdate</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) setanimationstartdate: (nsdate *) startTime</p></p><p><p></p></p><p><p>Sets the animation start Time.</p></p><p><p></p></p><p><p><strong>Setanimationdelay</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) setanimationdelay: (nstimeinterval) delay</p></p><p><p></p></p><p><p>Sets the delay time (in seconds <strong>)</strong>at which the animation begins.</p></p><p><p></p></p><p><p><strong>Setanimationcurve</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) setanimationcurve: (uiviewanimationcurve) curve</p></p><p><p></p></p><p><p>Sets the curve of the animation (that is, the time curve of the overall change of the animation: start fast last slow, start slow last fast, last slow, evenly linear).</p></p><p><p></p></p><p><p>The curve parameters are as Follows:</p></p><p><p></p></p><p><p>typedef ns_enum (nsinteger, Uiviewanimationcurve) {</p></p><p><p>Uiviewanimationcurveeaseinout,//slow at beginning and end</p></p><p><p>Uiviewanimationcurveeasein,//slow at beginning</p></p><p><p>Uiviewanimationcurveeaseout,//slow at end</p></p><p><p>Uiviewanimationcurvelinear</p></p><p><p>};</p></p><p><p></p></p><p><p></p></p><p><p><strong>Setanimationrepeatcount</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) setanimationrepeatcount: (float) repeatcount</p></p><p><p></p></p><p><p>Set the number of animations to repeat</p></p><p><p></p></p><p><p><strong>setanimationrepeatautoreverses</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) setanimationrepeatautoreverses: (BOOL) repeatautoreverses</p></p><p><p></p></p><p><p>Sets whether the animation performs a reverse Execution.</p></p><p><p>If set to Yes: animation will be performed: animation initial state animation animation completed state animation initial State.</p></p><p><p>If set to no: default value</p></p><p><p></p></p><p><p>Setanimationsenabled <strong>Method</strong></p></p><p><p></p></p><p><p>+ (void) setanimationsenabled: (BOOL) enabled</p></p><p><p></p></p><p><p>Sets whether the animation is available!</p></p><p><p>YES: the default Value.</p></p><p><p>NO: animation effect is disabled</p></p><p><p><strong>Note: only the animation is available, and the UI object that was changed in the animation still works. Only the animation effect is Disabled.</strong></p></p><p><p></p></p><p><p><strong>areanimationsenabled</strong> <strong>Method</strong></p></p><p><p></p></p><p><p>+ (BOOL) areanimationsenabled</p></p><p><p></p></p><p><p>Returns whether the animation effect is Disabled.</p></p><p><p></p></p><p><p><strong><span style="color: #ed1c24;">Encourage the use of block mode for more, more concise control!</span></strong><br><br></p></p><p><p>Actually found, this blog has been a bit long! A little bad taste!</p></p><p><p>however, looking back, Since the beginning of the reference to the core animation!</p></p><p><p><span style="color: #393939;">apple, The default simple animation, can be used</span> <strong>setanimationxxx</strong> A class of METHODS. But if, to make the animation more beautiful, complex, then I would like to test core animation!</p></p><p><p>Make a split, below to learn about core animation!</p></p><p><p>--------------------------------------------------------------------------------------------------------------- ---------------------</p></p><p><p></p></p><p><p>Let's get a code first!</p></p><p><p></p></p><p><p></p></p><p><p>[_imgpic Setimage:image];//set a new picture</p></p><p><p></p></p><p><p></p></p><p><p>Catransition *animation = [catransition animation];</p></p><p><p>[animation setduration:1.0];</p></p><p><p>[animation setfillmode:kcafillmodeforwards];</p></p><p><p>[animation settimingfunction:[camediatimingfunction functionwithname:kcamediatimingfunctioneaseout];</p></p><p><p>[animation settype:@ "rippleeffect"];//rippleeffect</p></p><p><p>[animation setsubtype:kcatransitionfromtop];</p></p><p><p>[_imgpic.layer addanimation:animation forkey:nil];</p></p><p><p></p></p><p><p>A vacant ah!</p></p><p><p></p></p><p><p>What is the relationship between UIView and Catransition two animations? Which one do you use?</p></p><p><p></p></p><p><p></p></p><p><p>One is at the UIView level.</p></p><p><p>One is to use catransition for lower levels of Control.</p></p><p><p>The first is that the Uiview,uiview approach may also be encapsulated in the lower layer using catransition, which can only be used for some simple, common effect presentation.</p></p><p><p>so, both, often in need of complex animation, should be used catransition bar.</p></p><p><p>(go) iOS Animation core Animation</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.