Types and implementation methods of iPhone animation Effects

Source: Internet
Author: User

There are two main ways to achieve beautiful iPhone animation effects: one is at the uiview level, and the other is to use catransition for lower-level control,
The first is uiview. The uiview method may also be encapsulated by catransition on the lower layer. It can only be used for some simple and common effects. Here, we will write a common sample code, for your reference.

View plaincopy to clipboardprint?

    [Uiview beginanimations: @ "curl" context: Nil]; // starts the animation.

  1. [Uiview setanimationduration: 0.75]; [uiview setanimationdelegate: Self];
  2. [Uiview setanimationtransition: uiviewanimationtransitioncurlup forview: myview cache: Yes]; [myview removefromsuperview];
  3. [Uiview commitanimations];

[Uiview beginanimations: @ "curl" context: Nil]; // The animation starts [uiview setanimationduration: 0.75]; [uiview setanimationdelegate: Self]; [uiview setanimationtransition: Previous forview: myview cache: Yes]; [myview removefromsuperview]; [uiview commitanimations];

The second method is relatively complicated, but if you want to better control it, you can use this method. For the basic usage method, refer to the following example:

View plaincopy to clipboardprint?

    Catransition * animation = [catransition animation];

  1. [Animation setduration: 1.25f]; [animation settimingfunction: [camediatimingfunction
  2. Functionwithname: kcamediatimingfunctioneasein]; [animation settype: kcatransitionreveal];
  3. [Animation setsubtype: kcatransitionfrombottom]; [self. View. layer addanimation: animation forkey: @ "reveal"];

Catransition * animation = [catransition animation]; [animation setduration: 1.25f]; [animation settimingfunction: [Animation: animation]; [animation settype: animation]; [animation setsubtype: kcatransitionfrombottom]; [self. view. layer
Addanimation: animation forkey: @ "reveal"];

The settype and setsubtype combinations are used here, which is relatively safe, because their parameters are defined in the official API. Their parameter descriptions can be referred to below:

View plaincopy to clipboardprint?

    Settype: four types can be returned:

  1. Kcatransitionfade fades out kcatransitionmovein to overwrite the source Image
  2. Kcatransitionpush launches kcatransitionreveal.
  3. Setsubtype: there can also be four types: kcatransitionfromright;
  4. Kcatransitionfromleft (default) kcatransitionfromtop;
  5. Kcatransitionfrombottom

Settype: four types can be returned: kcatransitionfade fade-out coverage overwrite the original image kcatransitionpush. The bottom of the release is shown as setsubtype: there can also be four types: kcatransitionfromright; kcatransitionfromleft

There is also a way to set the animation type, without setsubtype or settype.

View plaincopy to clipboardprint?

    [Animation settype: @ "suckeffect"];

[Animation settype: @ "suckeffect"];

Suckeffect here is the name of the effect. The following effects can be used:

View plaincopy to clipboardprint?

    Pagecurl page up

  1. Pageuncurl flip down a page rippleeffect dripping Effect
  2. Suckeffect: contraction effect. If a cloth is extracted from the Cube
  3. Oglflip flip up and down

Pagecurl flip one page up pageuncurl flip one page down rippleeffect drip effect suckeffect shrink effect, such as a piece of cloth is extracted from the Cube effect oglflip flip up and down effect

Finally, a common code is provided for your reference.

View plaincopy to clipboardprint?

    // Curl the image up or down

  1. Catransition * animation = [catransition animation]; [animation setduration: 0.35];
  2. [Animation settimingfunction: uiviewanimationcurveeaseinout];If(! Curled ){
  3. // Animation. type = @ "mapcurl"; animation. type = @ "pagecurl ";
  4. Animation. fillmode = kcafillmodeforwards; animation. endprogress = 0.99;
  5. }Else{// Animation. type = @ "mapuncurl ";
  6. Animation. type = @ "pageuncurl"; animation. fillmode = kcafillmodebackwards;
  7. Animation. startprogress = 0.01 ;}
  8. [Animation setremovedoncompletion: No]; [view exchangesubviewatindex: 0 withsubviewatindex: 1];
  9. [View addanimation: animation forkey "pagecurlanimation"]; // Disable User interaction where necessary
  10. If(! Curled ){
  11. }Else{
  12. } Curled =! Curled;

// Curl the image up or downcatransition * animation = [catransition animation]; [animation setduration: 0.35]; [animation settimingfunction: uiviewanimationcurveeaseinout]; If (! Curled) {// animation. type = @ "mapcurl"; animation. type = @ "pagecurl"; animation. fillmode
= Kcafillmodeforwards; animation. endprogress = 0.99;} else {// animation. type = @ "mapuncurl"; animation. type = @ "pageuncurl"; animation. fillmode = kcafillmodebackwards; animation. startprogress = 0.01;} [animation setremovedoncompletion: No]; [view exchangesubviewatindex: 0
Withsubviewatindex: 1]; [view addanimation: animation forkey "pagecurlanimation"]; // Disable User interaction where necessaryIf (! Curled) {} else {} curled =! Curled;

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.