iOS Learning _uidynamic (physical simulation) Learning notes

Source: Internet
Author: User

uidynamic: Can be thought of as a physical engine that simulates and emulates physical phenomena in real life such as: gravity, elastic collisions, etc.

steps to use:

1. Create the Physical emulator:

[[Uidynamicanimator alloc] Initwithreferenceview:]//view represents the scope of the physical simulation

2. Create the physical simulation behavior and add the simulation elements:

[[Uigravitybehavior alloc]initwithitems:];//is placed in an array

3. Add the physical simulation behavior to the emulator:

[Anim addbehavior:gravity]

My memory method (just the memory method, if you can remember not to see the memory method):

Simulator-Ocean

Simulation Behavior--ship

View--People

Create an emulator (SEA), create simulation behavior (ship), the boat to someone (view), the ship to the sea to add, you can soar.

Uidynamic provides several physical simulation behaviors

1. Gravity Behavior: Uigravitybehavior

2. Collision Behavior: Uicollisionbehavior

3. Catch-up behavior: Uisnapbehavior

4. Driving behavior: Uipushbehavior

5. Adhesion behavior: Uiattachmentbehavior

6. Dynamic element behavior: Uidynamicitembehavior

Examples of Use:

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event

{

Uidynamicanimator * animator = [[Uidynamicanimator Alloc]initwithreferenceview:self.containview];

Self.animator = animator;//Note Be sure to hold the physical emulator, or the animator will be released if you do not start

Uigravitybehavior * Behavior0 = [[Uigravitybehavior Alloc]initwithitems:@[self.testview]];

Uicollisionbehavior * Behavior1 = [[Uicollisionbehavior Alloc]initwithitems:@[self.testview]];

Behavior1.translatesreferenceboundsintoboundary = yes;//Sets the bounds of the view to the boundary

[Animator Addbehavior:behavior0];

[Animator Addbehavior:behavior1];

}

Relevant knowledge points and points of attention:

(1) Any object that complies with the Uidynamicitem protocol can perform simulations because UIView adds the Uidynamic protocol by default, so all UI controls can be physically emulated

(2) All simulation behaviors can be performed independently or simultaneously, and all physical simulation behaviors are inherited from Uidynamicbehavior

iOS Learning _uidynamic (physical simulation) Learning notes

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.