Testing for View Intersection
By reader request, Recipe 4-5 adds code to check whether two transformed views intersect. The code also works with views that have not been transformed so that you can use it with any two views, although it’s a bit pointless to do so. (You can use the CGRectIntersectsRect()
function for simple untransformed frames.) This custom intersection method works best for views whose frames do not represent their underlying geometry, like the one shown in Figure 4-4.
The intersectsView:
method applies an axis separation algorithm for convex polygons. For each edge of each view, it tests whether all the points in one view fall on one side of the edge and whether all the points of the other view fall on the other side. This ...
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.