So far, we have set up gravity and added some boundaries, including an invisible boundary for our date label. It is very common to respond to collisions by performing some sort of task. For instance, in a game, once an enemy collides with a bullet, we would destroy the enemy and increase the score.
We can track collisions by using collision notifications. In order to do so, we must have our class adopt
UICollisionBehaviorDelegate. Switch to
FoodDetailViewController.h and add the following protocol:
@interface FoodDetailViewController : UIViewController <UICollisionBehaviorDelegate>
Now switch back to
FoodDetailViewController.m and locate the code we wrote to create the collision behavior. Add the following line of code:
collision.collisionDelegate = self;
By setting the collision delegate, we can now use the following delegate method:
- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier...