The core animation realizes the book page turn effect loading animation

Source: Internet
Author: User

Often see some good animation load view, idle to write a book page flip style animation load view, the core technology is calayer+coreanimation.

Here's the point:

To create a separate layer:

/* Create a Calayer object using the class method */

Calayer * layer = [calayer layer];

/* Catransform is actually a struct and therefore cannot directly assign values to the inner element */

Catransform3d transform = layer.transform;

/* Set the stereo effect value of layer M34 to render a stereo effect for this value */

TRANSFORM.M34 = 10.5/-2000;

Layer.transform = transform;

/* Set the background color of the layer, note the Cgcolor type */

Layer.backgroundcolor = [K_color_stock[_currentindex%k_color_stock.count] cgcolor];

/* Sets the anchor point, which is the center point of the animation, the default is (two-dimensional environment) (0.5.0.5), respectively, the x-axis midpoint of the y-axis */

Layer.anchorpoint = Cgpointmake (0, 0.5);

Layer.frame = CGRectMake (200, 100, 30, 45);

/* Set the center point of the layer to be familiar with center of the UIView object */

Layer.position = Cgpointmake (K_IOS_WIDTH/2, k_ios_height/2-50);

[Self.layer Addsublayer:layer];

Create a page-flipping animation

/* Create a page-flipping animation */

Cabasicanimation *basic = [cabasicanimation animationwithkeypath:@ "TRANSFORM.ROTATION.Y"];

/* TRANSFORM.ROTATION.Y Animation Start value */

Basic.fromvalue = @ (-M_PI);

/* TRANSFORM.ROTATION.Y Animation End value */

Basic.tovalue = @ (0);

/* Whether to automatically revert back to the original state after the animation has ended */

basic.autoreverses = NO;

/* Animation execution times */

Basic.repeatcount = 1;

/* Animation Duration */

Basic.duration = 1.0;

/* Animated Fill mode */

Basic.fillmode = kcafillmoderemoved;

/* Set Agent */

Basic.delegate = self;

[Layer addanimation:basic forkey:@ "BASC"];

When multiple layer animations are added in the previous method, and the interval is 0.2s, there will be a left-to-right page-flipping animation effect. If you want to be more perfect, you can add these layers to an array, and after the left-to-right animation is complete, add a reverse animation to the layer in the array to animate the page-back. As follows:

The core animation realizes the book page turn effect loading animation

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.