IOS Core Animation Advanced techniques-visual effects

Source: Internet
Author: User
Tags border color

On three chapters:

    1. Layer Tree
    2. Layer's Homestay Map
    3. Layer geometry

This essay focuses on the visual effects of layers.

Rounded Corners:

    • Conrnerradius Property
    • This property controls the curvature of the Calayer layer corner, default 0.0 (right angle)
    • The curvature value controlled by this property affects only the background color without affecting the background picture or sublayer, and you can intercept everything in the layer by setting the Maskstobounds property to Yes;
    • Examples of Use:
    • myview.layer.cornerradius=20.0f;
    • Myview.layer.maskstobounds=yes;

Layer border:

    • BorderWidth and BorderColor Properties
    1. Two attributes together define the drawing style of the edge of the layer, drawing along the bounds of the layer, including the corner of the layer
    2. The border is drawn in the layer boundary, and before all child content
    • BorderWidth
      • In points, the default 0.0
    • BorderColor
      • Define border color, default black
      • is the Cgcolorref type
      • Examples of Use:
      • myview.layer.cornerradius=20.0f;
      • Myview.layer.maskstobounds=yes;
      • myview.layer.borderwidth=5.0f;
      • Myview.layer.bordercolor=[uicolor Bluecolor]. Cgcolor;

Shadow:

    • Shadowopacity Property
      • Default 0.0 (not visible), floating-point number between maximum range 1.0 (completely opaque)
      • Can be displayed under any intent layer
    • Change the performance of the Shadow by the following 3 properties:
      • Shadowcolor
        • Control shadow color, default black, belongs to Cgcolorref type
      • Shadowoffset
        • Controls the direction and distance of the shadow, which belongs to the Cgsize type, the default {0,-3}, which is a 3-point upward displacement of the shadow relative to the y-axis
      • Shadowradius
        • Controls the blur of the shadow, the larger the value the more blurred

Shadow cropping:

    • Shadow drawing differs from border drawing, and shadow drawing is based on the shape of the layer's content (the homestay, sub-view) rather than the boundary and corner radius
    • Conflicts occur when shadows are used with cropping: The shadow is usually outside the layer boundary, and if the Maskstobounds property is turned on at this point, the highlighted content in the layer is clipped, then the shadow effect of the entire layer setting disappears
    • Solution: Use two layers, an empty outer layer that only draws shadows, a neatline layer that uses Maskstobounds to clip the content, using examples:
      • The frame property of MyView and Myshadowview should be set to the same
      • myview.layer.cornerradius=20.0f;
      • Myview.layer.maskstobounds=yes;
      • myshadowview.layer.shadowopacity=0.5f;
      • Myshadowview.layer.shadowoffset=cgsizemake (0.0f,5.0f);
      • myshadowview.layer.shadowradius=5.0f;

Shadowpath Properties:

    • Specifies a shadow shape outside of the layer shape (as long as the shape of the Cgpath path can be constructed), is a cgpathref type (a pointer to Cgpath)
      • Examples of Use:
      • myview.layer.shadowopacity=0.5f;
      • Cgmutablepathref squarepath=cgpathcreatemutable ();
      • Cgpathaddrect (Squarepath,null,myview.bounds);
      • Myview.layer.shadowpath=squarepath;
      • Cgpathrelease (Squarepath);

Layer Masks:

    • Mask Property
      • belongs to the Calayer type and has the same drawing and layout properties as other normal layers, like a sublayer, relative to the parent layer layout, but not an ordinary sublayer that defines a portion of the visible area of the parent layer
      • This property allows the layer's homestay map to present a shape content that it wants to present.
      • This property is like an opaque black plank, and the property layer content is like a transparent part of the opaque plank, and when overridden on the parent layer that owns it, the parent layer shows only the transparent portion of the mask
      • Calayer mask Layer The real thing is that the mask diagram is not limited to static plots, and any layer that has layers can be used as the Mask property, which means that your mask can be generated in real time through code or even animations.
        • Examples of Use:
        • Calayer *masklayer=[calayer layer];
        • Masklayer.frame=myimageview.bounds;
        • UIImage *maskimage=[uiimage imagenamed:@ "Cone.png"];
        • masklayer.contents= (__bridge id) maskimage.cgimage;
        • Myimageview.layer.mask=masklayer;

Tensile Filtration:

    • Minificationfilter (Zoom Out) and magnificationfilter (enlarge picture) Properties
    • When the image needs to be displayed in different sizes, make the pixels on the original and create new pixels to display on the screen.
    • Calayer offers three methods of stretching filtration:
      • Kcafilterlinear
        • Images blur when magnification is large
      • Kcafilternearest
        • Fast, the picture will not blur, but will compress the picture, enlarge will show block
      • Kcafiltertrilinear
        • High performance and Low distortion
      • Both the minification and magnification default filters are Kcafilterlinear

Group Transparency:

    The Opacity property of the
    • shouldrasterize property
      • Calayer controls the transparency of the layer, corresponding to the Alpha property on the UIView, which affects the sub-hierarchy
      • It is worth noting that the Calayer O Pacity property setting transparency causes the parent layer and sublayer to have a more hierarchical outline of the problem
      • can implement group transparency for Yes by setting the Shouldrasterize property of Calayer To resolve the parent-child contour caused by transparency blending significantly
          • Use example:
          • cgrect frame=cgrectmake (0,0,150,50);
          • UIButton *button=[[uibutton Alloc]initwithframe:frame];
          • Button.backgroundcolor=[uicolor Whitecolor];
          • button.layer.cornerradius=10;
          • Frame=cgrectmake (20,10,110,30);
          • UILabel *label=[[uilabel Alloc]initwithframe:frame];
          • [email protected] "Hello World";
          • Label.textalignment=nstextalignmentcenter;
          • [Button Addsubview:label];
          • Button.layer.shouldrasterize=yes;
          • Button.layer.rasterizationscale=[uiscreen Mainscreen].scale;

IOS Core Animation Advanced techniques-visual effects

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.