IOS quartz2d Transparent Layer Transparencylayer

Source: Internet
Author: User

Recently studying iOS quartz2d graphics drawing engine-----> Transparent layer Transparencylayer


Transparent layer


Combining two or more objects to produce a combined shape is considered a single object, and the transparent layer is useful when you need to use effects on a set of objects .

How the transparent layer works
The transparent layer of the quartz2d is similar to the layers in many popular graphic applications, and the layers are independent entities,
Quartz maintains a transparent stack for each context, and the transparent layer can be nested, but because the layers are usually part of the stack, we cannot manipulate them individually,
Start a transparent layer by calling Cgcontextbegintransparencylayer ,
The function has two parameters (graphics context, Cfdictionary object) Dictionary objects are generally null
The graphics state parameter remains the same except for the alpha value (default = 1), the shadow (the default is off), the blending mode (normal for default), and other parameters that affect the final combination.


Effect:


Directly on the code, the annotations are clear and easy to understand

quartz2dviewfour.m//quartz2ddemoone////Created by the Emperor Phlogistic Demon on 16/5/23.//copyright©2016 year Emperor Phlogistic demon. All rights reserved.//#import ' Quartz2dViewFour.h ' @implementation quartz2dviewfour//only override Drawrect:if Perform custom drawing.//an empty implementation adversely affects performance during animation.-(void) DrawRect: (CGRect             Rect {//Drawing code/** * Transparent layer creates a combined graph by combining two or more objects, which is considered to be a single object, and the transparent layer is useful when you need to use effects on a set of objects The transparent layer works like a layer in many popular graphics applications, the layer is a separate entity, Quartz maintains a transparent stack for each context, and the transparent layer can be nested, but because the layer is usually part of the stack, the quartz2d        As we cannot manipulate them alone, starting a transparent layer by calling Cgcontextbegintransparencylayer, the function has two parameters (graphics context, Cfdictionary object) The Dictionary object is generally null                       The graphics state parameter remains the same except for the alpha value (default = 1), the shadow (the default is off), the blending mode (normal for default), and other parameters that affect the final combination.  * Transparent layer working method * Start transparent layer operation, you can draw any object that you want to display on the layer, the drawing operation in the specified context will be treated as a composite object on a transparent background, when the background is drawn as a target cache independent of the graphics context,        We call the function Cgcontextendtransparencylayer. Quartz the combined object into context and uses the context's global alpha value, shadedand cropping regions Act on the combined object. Drawing in the transparent layer requires three steps: 1. Call Function Cgcontextbegintransparencylayer 2. Draw the object 3 that you want to combine in the transparent layer.        Call function Cgcontextendtransparencylayer */[self transparencylayerwithwidth:300 height:300]; }-(void) Transparencylayerwithwidth: (float) Width height: (float) height{cgcontextref context =    Uigraphicsgetcurrentcontext ();    Sets the offset of the shadow cgsize Myshadowoffset = Cgsizemake (10,-20);        Cgcontextsetshadow (Context, myshadowoffset, 10);        Start transparent layer Cgcontextbegintransparencylayer (context, NULL);    The object Cgcontextsetrgbfillcolor (context, 0, 1, 0, 1) is drawn in the transparent layer that needs to be combined;        Cgcontextfillrect (Context, CGRectMake (Width/3 +, HEIGHT/2, WIDTH/4, HEIGHT/4));    Cgcontextsetrgbfillcolor (context, 0, 0, 1, 1);        Cgcontextfillrect (Context, CGRectMake (WIDTH/3-WIDTH/4, HEIGHT/2-in-the-());    Cgcontextsetrgbfillcolor (context, 1, 0, 0, 1);        Cgcontextfillrect (Context, CGRectMake (WIDTH/3, HEIGHT/2-A, WIDTH/4, HEIGHT/4)); DrawCompletes the end transparent layer operation Cgcontextendtransparencylayer (context);} @end




IOS quartz2d Transparent Layer Transparencylayer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.