Graphics Reference
In-Depth Information
This behavior is understandable from a technical perspective, but it is unlikely to be the
effect that you wanted. If you want to clip the contents and cast a shadow, you need to use
two layers: an empty outer layer that just draws the shadow, and an inner one that has
masksToBounds enabled for clipping content.
If we update our project to use an additional view wrapped around the clipping view on the
right, we can solve the problem (see Figure 4.9).
Figure 4.9 An additional shadow-casting view around the clipping view on the right
We attach the shadow only to the outermost view, and enable clipping only on the inner
view. Listing 4.3 shows the updated code, and Figure 4.10 shows the result.
Listing 4.3 Using an Additional View to Solve Shadow Clipping Problems
@interface ViewController ()
@property ( nonatomic , weak ) IBOutlet UIView *layerView1;
@property ( nonatomic , weak ) IBOutlet UIView *layerView2;
@property ( nonatomic , weak ) IBOutlet UIView *shadowView;
@end
@implementation ViewController
Search WWH ::




Custom Search