2.3. Animating Your UI Components with a Push
Problem
You want to “flick” your views from one point to another.
Solution
Initialize a behavior object of type UIPushBehavior
using its initWithItems:mode:
method, and for the mode,
pass the value of UIPushBehaviorModeContinuous
. Once you are ready to start pushing the items toward an angle,
issue the setAngle:
method on the
push behavior to set the angle (in radians) for the behavior.
After that, you will need to set the
magnitude, or the force behind the push. You can
set this force using the setMagnitude:
method of the push behavior. The
magnitude is calculated in this way: each magnitude of 1 point will
result in acceleration of 100 points per second squared for your target
views.
Discussion
Push behaviors, especially continuous pushes, are very useful. Let’s say you are working on a scrapbook iPad app, and on top of the screen, you have created three slides, each representing one of the scrapbook pages that the user has created. On the bottom of the screen, you have various pictures that the user can drag and drop into the pages. One way to allow the user to do this is to add a tap gesture recognizer (see Recipe 10.5) to your reference view to track the tap and allow the pictures to be moved onto the target slide, which will, in turn, simulate the dragging. The other, and perhaps better, way of doing this is to use the push behavior that Apple has introduced into UIKit.
The push behavior is of type UIPushBehavior
and has a magnitude ...
Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.