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