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

Using motion in our app

In addition to UIKit Dynamics, we can also use UIMotionEffects to adjust the user interface when a device is tilted horizontally. UIMotionEffects is an abstract class that works best when subclassed. Apple has already made a subclass of UIMotionEffects that will cover almost all use cases of motion in your apps. This subclass is the UIInterpolatingMotionEffect class.

The UIInterpolatingMotionEffect instance is initialized with a key path and a type. The type is what defines vertical and horizontal motions. The class will automatically set the key value path based on the device's movements.

In our viewDidLoad method, add the following code at the bottom:

UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];

horizontalMotionEffect.minimumRelativeValue = @(-30);
horizontalMotionEffect.maximumRelativeValue = @(30);

[self.foodImageView addMotionEffect...