In UIKit Dynamics, when you want to animate changing the center, you'd add a UISnapBehavior
to your UIDynamicAnimator
(removing any prior snap behavior first). For example, create a property for the UISnapBehavior
, and then your tap gesture recognizer can snap it to that point (honoring your UICollisionBehavior
), like so:
- (void)handleTap:(UITapGestureRecognizer *)gesture
{
if (self.snap)
[self.animator removeBehavior:self.snap];
CGPoint point = [gesture locationInView:gesture.view];
UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:self.viewToAnimate snapToPoint:point];
[self.animator addBehavior:snap];
self.snap = snap;
}
You can control the "bounciness" by adjusting the damping
property of the UISnapBehavior
. If you don't like it rotating the view as it's snapping, you can also add a UIDynamicItemBehavior
with allowsRotation
set to NO
.