Kinetics of Uidynamicanimator Uikit

Source: Internet
Author: User

Perhaps there is no such need at work and there is little understanding of uidynamicanimator. Here to do a simple introduction;

Uikit Dynamics is a simulation of real-world characteristics, mainly Uidynamicanimator class, through the different behaviors of the class to achieve some dynamic characteristics;

1. Initialization

Uidynamicanimator has two kinds of initialization methods;

Let  animator = Uidynamicanimator (ReferenceView:self.view)

Self.view represents a reference attempt to specify the scope of the physical simulation

Animator = Uidynamicanimator.init (collectionviewlayout: < #T # #UICollectionViewLayout #>)

Not all objects can do physical simulations, elements that are capable of physical emulation are subject to the Uidynamicitem protocol, and UIView adhere to the protocol, so any UI control can be physically emulated.

The Uicollectionviewlayoutattributes class also adheres to the Uidynamicitem protocol by default, so it can also be emulated

2. Physical simulation Behavior

Uidynamicanimator has the following physical simulation behaviors:

Uigravitybehavior: Gravity Behavior

Uicollisionbehavior: Collision Behavior

Uisnapbehavior: Snapping behavior

Uipushbehavior: Driving behavior

Uiattachmentbehavior: Adhesion behavior

Uidynamicitembehavior: Dynamic Elemental Behavior

The physical simulation behavior is added to the emulator to start the simulation operation;

3. Common methods of Uidynamicanimator

Add a physical behavior animator. Addbehavior (< #T # #behavior: uidynamicbehavior# #UIDynamicBehavior #>)//Remove a physical behavior animator. Removebehavior (< #T # #behavior: uidynamicbehavior# #UIDynamicBehavior #>)//Remove all physical behavior animator. Removeallbehaviors ()

4. Actual use (take the driving behavior as an example)

Animator.removeallbehaviors () Let push = Uipushbehavior.init (items: [Self.gravity,self.push], mode: uipushbehaviormode.instantaneous) Push.magnitude = 1  //The magnitude of the push must be initialized, and the magnitude of the magnitude represents the speed of the push animator. Addbehavior (push)// Control is rolled out view

Add one more collision behavior

Collision = Uicollisionbehavior.init (items: [Self.gravity,self.push]) Collision.translatesreferenceboundsintoboundary = Truecollision.collisionmode = uicollisionbehaviormode.everything  //Here the mode of choice you can constantly debugging to check   especially mixing effects such as if I write the push mode as continuous continuous push, then the blending effect of the control will be affixed to the edge of the reference graph is not moving animator. Addbehavior ( Collision)

Kinetics of Uidynamicanimator Uikit

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.