Time in iOS animation development, ios animation Development

Source: Internet
Author: User

Time in iOS animation development, ios animation Development
Overview

In an animation, we specify the animation duration. For example

scaleAnimation.duration = self.config.appearDuration

So how is this time defined? Is it absolute time?

Hierarchical Time Structure

The display position of a layer on the screen is defined based on the position of the parent layer and its offset relative to the parent layer.
Similarly, each layer has its own time space. When calculating the local time, you need to calculate the local time according to the time of the parent layer and certain conversion rules.
This rule isCAMediaTimingProtocol. EveryCALayerAndCAAnimationThis Protocol is implemented.
Bytes
Bytes

Concept of time CAMediaTimingExample of protocol Time conversion formula

A simple example is used to describe the influence 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.
About begintime

According to Formula
\[
T = max \ left \ {(t_p-begintime), 0 \ right \} * speed + offset
\]
How should we specify begintime here? If you want to delay the execution of an animation added to the layer by 5s, should you set begintime to 5 directly?
Because begintime is the time offset from the parent object (layer. Since the layer may have existed a long time ago, \ (t_p \) is a large value for animations. If you specify begintime as 5 s, \ (t \) will be a large value. The correct method is to set begintime to 5 s + after the layer is added to the parent layer, the time spent is called addtime.

    animation.beginTime = addTime + delay;

How to Get addtime

addTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
Reference

Control animation time
Control animation time
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.