Retrieving Transform Properties

When working with transforms, iOS can provide an affine representation of the transform associated with a view. This representation will not, however, tell you exactly how much the view has been scaled or rotated. Recipe 4-5 addresses this problem by calculating the scale and rotation via a simple UIView category.

An affine matrix is stored in iOS as a structure of six fields: a, b, c, d, tx, and ty. Figure 4-4 shows how these values relate to their positions in the standard affine matrix. Simple math allows you to derive scaling and rotation from these, as shown in Recipe 4-5. Note how you can retrieve the tx and ty values directly from the transform. If linear algebra isn’t in your wheelhouse, don’t worry; you ...

Get The Core iOS Developer’s Cookbook, Fifth Edition 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.