Our last behavior we will cover in this book is the
UISnapBehavior class. UIKit Dynamics provides a built-in behavior that will snap an item from its starting point to a specified end point with built-in damping. Let's have our food image view snap from the top of the screen into its final position.
viewDidLoad and remove all of our gravity and collision code (keep our animator). Add the following code to
UISnapBehavior *snapBehaviour = [[UISnapBehavior alloc] initWithItem:self.foodImageView snapToPoint:CGPointMake(160, 202)]; snapBehaviour.damping = 0.65f; [animator addBehavior:snapBehaviour];
Here we allocate new
init options with our food image view. We also pass the point we want the item to snap to, in this case, the final position of the image view. We set the damping value to be a bit higher to give a milder spring effect (the lower the number, the more springy the item will be).
The last thing to do is to change the starting point...