Animation development in iOS (Overview), ios Overview

Source: Internet
Author: User

Animation development in iOS (Overview), ios Overview
I. Introduction

When using animations in iOS development, you can setduration,speed,begintime,offsetTo set the animation duration, speed, start time, and start offset.
A simple example is used to describe the functions of each parameter. The animation is very simple. A Red Square moves from left to right. The animation lasts for 1 s and is not repeated. The effect is as follows.
CFTimeInterval currentTime = CACurrentMediaTime(); CFTimeInterval currentTimeInLayer = [self.testLayer convertTime:currentTime fromLayer:nil]; CFTimeInterval addTime = currentTimeInLayer; anim.beginTime = 0.3 + addTime; [anim setTimeOffset:0.5]; [anim setSpeed:2];

After modification, the effect is as follows:

Ii. Hierarchical Time Structure

According to the document,CMediaTimingThe protocol constructs a hierarchical Time System and uses this hierarchical time system to coordinate the time of each layer and animation.
This Protocol isCAAnimationAndCALayerCompliance: each object that complies with the Protocol corresponds to onetime space. Based on the relationship between objects, differenttime spaceHierarchical relationship. For example, if Layer A has A subLayer Btime spaceIs corresponding to layer B.time spaceOfparent time space. Everytime spaceThe time value is based onparent time spaceAndbegintime,speedAccording to certain rules.

To facilitate understanding of the hierarchical time system, Let's first look at how the display position of the layer on the screen is determined, and then make an analogy.

Layer level. Determine the position of sublayer1 on the screen in three steps.

Similarly, to determine the time in sub1ayer1, three steps are required.

Compared with determining the location of a layer, determining the time is somewhat complicated. The following two points are proposed:

III, active local time

This conversion aims to process the location of the object at the current level on the time line of the parent level, as well as the relationship between the time passing speed between the current level and the parent level.
Attributes related to this conversion include:beginTime,speedAndtimeOffset

Slaveparent timeToactive local timeThere is a formula for reference.

t = (tp - begin) * speed + offset
IV, basic local time

This conversion aims to process repeat at the current level, and whether to perform reverse playback before replay.

For example, the current level is an animation (CAAnimationComplianceCAMediaTimingProtocol ),durationIt is 1 s, after the first conversionactive local timeIt is 5.5 s. IfrepeatCountIs 10, after the second conversion,basic local timeIt will be 0.5 s, so the animation shows half of the State.

V. Example

Based on this knowledge, you can explain the effect of setting parameters at the beginning of the article.
When an animation is added to a layertime spaceAdded to the hierarchical time system, corresponding to the layertime spaceSub-level.

6. More applications

UnderstandCAMediaTimingAfter the protocol, you can achieve a lot of animation effects.

Apple has already given us the tools, so you can imagine what kind of products you can make.

Reference

Control animation time
Control animation time (Chinese Version above)
Time Warp in Animation

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.