Graphics Reference
In-Depth Information
Figure 3.8 The green view is positioned underneath the red one in the view hierarchy.
We would expect this drawing order to be reflected in the actual app, as well, but if we
increase the zPosition of the green view (see Listing 3.3), we find that the order is
reversed (see Figure 3.9). Note that we don't need to increase it by much; views are
infinitely thin, so even a 1-point increase in the zPosition brings the green view in front
of the red one. A smaller value such as 0.1 or 0.0001 would also work, but be wary of using
very tiny values because this can lead to visual glitches as a result of rounding errors in the
floating-point calculations.
Listing 3.3 Adjusting zPosition to Change the Display Order
@interface ViewController ()
@property ( nonatomic , weak ) IBOutlet UIView *greenView;
@property ( nonatomic , weak ) IBOutlet UIView *redView;
@end
@implementation ViewController
- ( void )viewDidLoad
{
[ super viewDidLoad ];
Search WWH ::




Custom Search