Tappable Overlays

A custom overlay can present information as well as limit interaction. You can easily expand the overlay approach from Recipe 3-3 so that the view dismisses itself on a touch. When tapped, the view removes itself from the screen. This behavior makes the view particularly suitable for showing information in a way normally reserved for the UIAlertView class:

@interface TappableOverlay : UIView @end @implementation TappableOverlay - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {     // Remove this view when it is touched     [self removeFromSuperview]; } @end

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.