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
//Create a UIDynamicAnimator
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:aView];
//Add UIDynamicBehaviors to it (gravity, collisions, etc.)
// gravity
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] init];
[animator addBehavior:gravity];
// or collision
UICollisionBehavior *collider = [[UICollisionBehavior alloc] init];
[animator addBehavior:collider];
//Add UIDynamicItems (usually UIViews) to the UIDynamicBehaviors
id <UIDynamicItem> item1 = ...;
id <UIDynamicItem> item2 = ...;
[gravity addItem:item1];
[collider addItem:item1];
[gravity addItem:item2];
The items have to implement the UIDynamicItem protocol â¦
@protocol UIDynamicItem
@property (readonly) CGRect bounds;
@property (readwrite) CGPoint center;
@property (readwrite) CGAffineTransform transform;
@end
UIView implements this @protocol.
If you change center or transform while animator is running, you must call UIDynamicAnimatorâs
- (void)updateItemUsingCurrentState:(id <UIDynamicItem>)item;
UIDynamicBehavior
Superclass which is inherited by the primitive dynamic behavior classes: UIAttachmentBehavior, UICollisionBehavior, UIGravityBehavior, UIDynamicItemBehavior, UIPushBehavior, and UISnapBehavior.
å¯ä»¥å®¢å¶åsubclass combination
- (void)addChildBehavior:(UIDynamicBehavior *)behavior
behaviorså¯ä»¥ç¥éèªå·±ä½æ¼åªå UIDynamicAnimator
@property UIDynamicAnimator *dynamicAnimator;
This get called when the dynamic behavior is added to, or removed from, a dynamic animator.
- (void)willMoveToAnimator:(UIDynamicAnimator *)dynamicAnimator
Parameters : dynamicAnimator
The dynamic animator that the behavior is being added to, or è¥è¢«animatorç§»é¤: nil.
UIDynamicBehavior ç¼ççç¬é
ä½é叏䏿æ¾å¤ªå¤çéç®å¨è£¡é¢
uiPushBehavior.action = ^{
NSLog(@"action block");
};
References
http://furnacedigital.blogspot.tw/2013/10/uikit-dynamics.html http://furnacedigital.blogspot.tw/2013/10/uikit-dynamics_17.html