A couple of thoughts:
If you want to slow down the push over time, so that a single push translates to some finite distance traveled, you have to (a) add a linear
resistance
(so it slows down); and (b) useUIPushBehaviorModeInstantaneous
(so it doesn't keep pushing). To addresistance
, you would add aUIDynamicItemBehavior
:UIDynamicItemBehavior *resistanceBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[viewToAnimate]]; resistanceBehavior.resistance = 1.0; [self.animator addBehavior:resistanceBehavior];
In terms of controlling the distance that each push generates, that's a combination of (a) the magnitude of the
pushDirection
vector you employ; (b) theresistance
you apply to your item in theUIDynamicItemBehavior
; (c) the size of item you're moving; and (d) thedensity
you apply to your item inUIDynamicItemBehavior
. It's probably best to play around with those variables until you achieve the desired distance for a single push.If, on the other hand, you want to "accelerate a
UIView
over time", then rather than aUIPushBehaviorModeInstantaneous
, you would apply aUIPushBehaviorModeContinuous
. By continuously applying a force, it will continue to accelerate in thepushDirection
until thatUIPushBehavior
is removed from theUIDynamicAnimator
.