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