Book Image

Application Development in iOS 7

By : Kyle Begeman
Book Image

Application Development in iOS 7

By: Kyle Begeman

Overview of this book

Table of Contents (15 chapters)
Application Development in iOS 7
About the Author
About the Reviewers

Creating invisible boundaries

We are going to take a slightly different approach to this problem. Our label is only a point of reference for where we want to add a boundary that will stop our food image view. Because of this, the label does not need to be associated with any UIKit Dynamic behaviors. Remove self.foodDateLabel from the following code:

collision = [[UICollisionBehavior alloc] initWithItems:@[self.foodImageView, self.foodDateLabel]];

Instead, add the following code to the bottom of viewDidLoad but before we add our collision behavior to the animator:

// Add a boundary to the top edge
CGPoint topEdge = CGPointMake(self.foodDateLabel.frame.origin.x + self.foodDateLabel.frame.size.width, self.foodDateLabel.frame.origin.y);
[collision addBoundaryWithIdentifier:@"barrier" fromPoint:self.foodDateLabel.frame.origin toPoint:topEdge];

Here we add a boundary to the collision behavior and pass some parameters. First we define an identifier, which we will use later, and then we pass the food...