You can also use a UIAttachmentBehavior
to achieve a similar affect as UISnapBehavior
, with greater control over speed. For example:
UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:viewToAnimate attachedToAnchor:viewToAnimate.center];
[self.animator addBehavior:attachment];
attachment.frequency = 20.0;
attachment.damping = 1.0;
attachment.anchorPoint = newPoint;
By increasing frequency
to values above 1.0
will make it faster. By decreasing frequency
to values between 0.0
and 1.0
, will make it slower (or by adding resistance
values greater than 1.0
to your UIDynamicItemBehavior
).
If you find it oscillating at that final location when using this frequency
value, add some resistance to the item, too:
UIDynamicItemBehavior *resistance = [[UIDynamicItemBehavior alloc] initWithItems:@[viewToAnimate]];
resistance.resistance = 100.0;
[self.animator addBehavior:resistance];