Set up physics relating animatable objects and let them run until they resolve to stasis.Easily possible to set it up so that stasis never occurs, but that could be performance problem.
只要物件繼承UIView類別,就自動擁有動態行為的能力.
STEPS
1. Create a UIDynamicAnimator
UIDynamicAnimator*animator=[[UIDynamicAnimatoralloc]initWithReferenceView:aView];#If animating views, all views must be in a view hierarchy with reference view at the top.
2. Add UIDynamicBehaviors to it (gravity, collisions, etc.)
#Create and add UIDynamicBehaviors.UIGravityBehavior*gravity=[[UIGravityBehavioralloc]init];[animatoraddBehavior:gravity];
3. Add UIDynamicItems (usually UIViews) to the UIDynamicBehaviors.
#The items have to implement the UIDynamicItem protocol ... @protocolUIDynamicItem@property(readonly)CGRectbounds;#drawing area of the item.@property(readwrite)CGPointcenter;#the position of the item.@property(readwrite)CGAffineTransformtransform;@end
-(void)updateItemUsingCurrentState:(id<UIDynamicItem>)item;#If you change center or transform while animator is running, you must call UIDynamicAnimator’s
@propertyUIPushBehaviorModemode;# Continuous or Instantaneous@propertyCGVectorpushDirection;@propertyCGFloatmagnitude/angle;# magnitude 1.0 moves a 100x100 view at 100 pts/s/s
the behavior will be sent this message when its animator changes.