O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TRANSFORMING VIEWS

You can use the NSTimer class to simulate a simple animation by continuously changing the position of the Image View, but you can also use the transformation techniques supported by the iOS SDK to achieve the same effect.

Transforms are defined in Core Graphics (a C-based API that is based on the Quartz advanced drawing engine; you use this framework to handle things such as drawings, transformations, image creation, etc.), and the iOS SDK supports standard affine 2D transforms. You can use the iOS SDK to perform the following affine 2D transforms:

  • Translation — Moves the origin of the view by the amount specified using the x and y axes
  • Rotation — Moves the view by the angle specified
  • Scaling — Changes the scale of the view by the x and y factors specified

image NOTE An affine transformation is a linear transformation that preserves co-linearity and ratio of distances. This means that all the points lying on a line initially will remain in a line after the transformation, with the respective distance ratios between them maintained.

Figure 13-7 shows the effects of the various transformations.

Translation

To perform an affine transform on a view, simply use its transform property. Recall that in the previous example, you set the new position of the view through its center property:

imageView.center = CGPointMake(imageView.center.x + delta.x, imageView.center.y + ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required