iOS Development extension-uidynamic (Brief introduction)

Source: Internet
Author: User

iOS Development extension-uidynamic (Brief introduction)

First, Brief introduction

1. What is Uidynamic

Uidynamic is a new technology introduced from iOS 7 and belongs to the Uikit framework

Can be thought of as a physical engine capable of simulating and simulating physical phenomena in real life.

such as: gravity, elastic collision and other phenomena

2. The value of the physics engine

Widely used in game development, the classic success story is "Angry Birds"

Enable developers to achieve cool physics simulations away from the physics equation

Improve the game development efficiency, produce more excellent fun physics simulation game

3. Well-known 2D physics engine

Box2d

Chipmunk

Second, the use of steps

To use uidynamic to achieve physical simulation, the following steps are outlined below

(1) Create a physical emulator (by the way, set the simulation scope)

(2) create the corresponding physical simulation behavior (by adding physical simulation elements by the way)

(3) adding Physical simulation behavior to the physical emulator? Start simulation

Iii. Related Notes

1. Three Concepts

(1) Who wants to perform physical simulations?

  physical emulation element (Dynamic Item)

(2) What kind of physical simulation effect does it perform? What kind of animated effect?

  Physical Simulation Behavior (Dynamic Behavior)

(3) Allow physical simulation elements to perform specific physical simulation behavior

  Physical Emulator (Dynamic Animator)

2. Physical simulation elements

Note :

Not all objects can do physical simulation elements

Not all objects can be physically emulated

Physical simulation element elements:

Any object that complies with the Uidynamicitem protocol

UIView has complied with the Uidynamicitem protocol by default, so any UI control can do a physical simulation

The Uicollectionviewlayoutattributes class also complies with the Uidynamicitem protocol by default

3. Physical simulation Behavior

(1) Uidynamic provides the following physical simulation behavior

Uigravitybehavior: Gravity Behavior

Uicollisionbehavior: Collision Behavior

Uisnapbehavior: Snapping behavior

Uipushbehavior: Driving behavior

Uiattachmentbehavior: Adhesion behavior

Uidynamicitembehavior: Dynamic Elemental Behavior

(2) physical simulation behavior Notice

All of the above physical simulation behaviors are inherited from Uidynamicbehavior

All Uidynamicbehavior can be carried out independently.

When combined with multiple behaviors, you can achieve some more complex effects

4. Physical Emulator

(1) Physical emulator information

It allows physical simulation elements to perform physical simulation behavior

It is an object of type Uidynamicanimator

(2) Initialization of Uidynamicanimator

-(Instancetype) Initwithreferenceview: (UIView *) view;

View parameter: is a reference view that represents the scope of a physical simulation

5. Description of the Physical emulator

(1) Common methods of Uidynamicanimator

-(void) Addbehavior: (Uidynamicbehavior *) behavior; //Add 1 physical emulation behavior

-(void) Removebehavior: (Uidynamicbehavior *) behavior; //Removal of 1 physical simulation behaviors

-(void) removeallbehaviors; //Remove all physical emulation behaviors that were previously added

(2) Common properties of Uidynamicanimator

@property (nonatomic, readonly) uiview* Referenceview; // Reference View

@property (nonatomic, readonly, copy) nsarray* behaviors; All physical emulation behaviors added to the physical emulator

@property (Nonatomic, readonly, getter = isrunning) BOOL running; //Whether physical simulation is in progress

@property (nonatomic, assign) ID <UIDynamicAnimatorDelegate> delegate; //proxy object (can listen to the simulation process of the physical emulator, such as start and end)

iOS Development extension-uidynamic (Brief introduction)

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.