Created
February 20, 2012 16:23
-
-
Save ksm/1869980 to your computer and use it in GitHub Desktop.
CALayer masking in drawLayer:inContext (to avoid layer.cornerRadius performance hit)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Source: Apple Developer - Understanding iOS View Compositing | |
Note: setting view.layer.cornerRadius and .masksToBounds | |
sends the view for rending to an offscreen buffer. | |
We want to avoid unnecessary rendering passes. | |
Let the context do the work. | |
*/ | |
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { | |
CGRect rect = layer.bounds; | |
[[UIBezierPath bezierPathWithRoundedRect:rect | |
cornerRadius:10.0] addClip]; | |
[image drawInRect:rect]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment