Learning Animation Summary-visual effects

Source: Internet
Author: User

Rounded Corners
Calayer has a property called Conrnerradius that controls the curvature of the layer's corners. It is a floating-point number that defaults to 0 (0 is right-angled), but you can set it to any value. By default, this curvature value affects only the background color without affecting the background picture or sublayer. However, if you set Maskstobounds to Yes, everything inside the layer will be intercepted.
When you set the fillet of a view or layer, it is not affected by each other.

UIView *temp = [[UIView alloc]initwithframe:cgrectmake ( -, -, $, $)];[Self. ViewADDSUBVIEW:TEMP];Temp. BackgroundColor= [Uicolor Bluecolor];Calayer * layer = [Calayer layer];Layer. Frame= CGRectMake ( -, -, -, -);Layer. BackgroundColor= [Uicolor Yellowcolor]. Cgcolor;[Temp. LayerAddsublayer:layer];Layer. Cornerradius=20.0F;UIView *TEMP2 = [[UIView alloc]initwithframe:cgrectmake ( -, -, $, $)];[Self. ViewADDSUBVIEW:TEMP2];Temp2. BackgroundColor= [Uicolor Bluecolor];Temp2. Layer. Cornerradius=.F;Calayer * Layer2 = [Calayer layer];Layer2. Frame= CGRectMake ( -, -, -, -);Layer2. BackgroundColor= [Uicolor Yellowcolor]. Cgcolor;[Temp2. LayerADDSUBLAYER:LAYER2];

When you change the position of the layer of the two view to 50,-50, the layer is outside the view.

You can set the Maskstobounds property to Yes when you don't want to go outside. I set the maskstobounds of Temp2 to Yes. It becomes the following effect.

Layer Border
Calayer Two other very useful properties are borderwidth and bordercolor. Together, they define the drawing style for the edges of the layer. This line (also called a stroke) is drawn along the bounds of the layer and also contains the corners of the layer.
BorderWidth is a floating-point number that defines the border thickness in points, with the default of 0.borderColor defining the color of the border, and the default is black.
BorderColor is a cgcolorref type, not a uicolor, so it is not a built-in object for cocoa. However, you must also know that the layer refers to bordercolor, although the attribute declaration does not prove it. The behavior of Cgcolorref in quoting/releasing is very similar to that of NSObject. However, the OBJECTIVE-C syntax does not support this practice, so the Cgcolorref attribute can only be declared by the Assign keyword, even if it is a strong reference.

I'll look at the effect by setting the temp border.

    temp.layer.borderWidth10.0f;

The

temp changes with a border, but the border does not calculate the shape of the homestay or sublayer, and the border will still be drawn along the boundary of the layer if the layer's sublayers are beyond the bounds, or if the boarding chart has a transparent mask in the transparent area

Shadows
Shadows can often reach the effect of layer depth hints. It can also be used to emphasize the layers and priorities being displayed (such as a pop-up box before other views), but sometimes they are purely decorative purposes.
Give the Shadowopacity property a value that is greater than the default value (that is, 0), and the shadow can be displayed below any layer of intent. Shadowopacity is a floating-point number that must be between 0.0 (invisible) and 1.0 (completely opaque). If set to 1.0, a slightly blurred black shadow is displayed slightly above the layer. To change the performance of the shadow, you can use another three properties of Calayer: Shadowcolor,shadowoffset and Shadowradius.
Obviously, the Shadowcolor property controls the color of the shadow, and like BorderColor and BackgroundColor, its type is also cgcolorref. Shadows are black by default, and most of the time you need shadows that are black.
The Shadowoffset property controls the direction and distance of the shadow. It is a cgsize value, the width controls the lateral displacement of the shadow, and the height controls the longitudinal displacement. The default value for Shadowoffset is {0,-3}, meaning that the shadow has an upward displacement of 3 points relative to the y-axis.
Why do you want to default up the shadow? Although core animation evolved from a layer suite (which can be thought of as a private animation frame created for iOS), it was on Mac OS, as mentioned earlier, the y-axis is reversed. This causes the default 3-point displacement of the shadow to be upward. On Mac, the default value of Shadowoffset is shaded downward, so you can understand why the shadow direction on iOS is up.
The Shadowradius property controls the blur of the shadow, and when its value is 0, the shadow has a very definite boundary line like the view (black, similar to the previous border). When the value is getting bigger, the boundary line will look more and more blurred and natural. Apple's own application design is more in favor of natural shadows, so a non-0 value is more appropriate.
Set the shadow again when you must set the shadowopacity, I did not set the initial display (...). )。
I set the Temp2 and Layer2 to shadow. For the temp boarding chart oil is transparent, shadow clipping calculates the shadow shape, which perfectly matches the layer shape to create a shadow, such as.

Temp. Layer. Contents= (__bridge ID _nullable) (IM. Cgimage);Temp. Layer. Shadowopacity=5.0F;Temp. Layer. Shadowoffset= Cgsizemake (2,5);Temp. Layer. Shadowradius=10.0F;Layer2. Shadowopacity=5.F;Layer2. Shadowoffset= Cgsizemake (-5,9);Layer2. Shadowradius=10.0F;Temp2. Layer. Shadowopacity=5.F;Temp2. Layer. Shadowoffset= Cgsizemake (-5,9);Temp2. Layer. Shadowradius=10.0F;

Shadowpath
The Shadowpath property specifies any shadow shape, Shadowpath is a cgpathref type (a pointer to Cgpath). Cgpath is a core graphics object used to specify any vector graphic. This property allows us to specify the shape of the shadow separately from the layer shape.

    CGMutablePathRef squarePath = CGPathCreateMutable();    CGPathAddEllipseInRect(squarePath, NULL, temp.bounds);    temp.layer.shadowPath = squarePath;


If it is a rectangle or a circle, it is fairly straightforward to use Cgpath. But if it's a more complicated graph, the Uibezierpath class would be more appropriate, and it's a objective-c wrapper class provided by Uikit on cgpath basis.
Layer Mask (this place is not deep)
Calayer There is a property called mask that solves this problem. This property is itself a calayer type, with the same drawing and layout properties as other layers. It is similar to a sublayer, which is laid out relative to the parent layer (that is, the layer that owns the property), but it is not an ordinary sublayer. Unlike the sublayers that are drawn in the parent layer, the mask layer defines a portion of the visible area of the parent layer. The color property of the
mask layer is irrelevant, and what really matters is the outline of the layer. The Mask property is like a cookie cutter, where the solid portion of the mask layer is preserved and the others are discarded. If the mask layer is smaller than the parent layer, only the content inside the mask layer is what it cares about, and everything else will be hidden. (This mask is added later)

    [[UIImageView alloc]initWithImage:[UIImage  imageNamed:@"10.pic_hd"]];    ima.frame = CGRectMake(00150150);    [temp addSubview:ima];    //遮罩    CALayer *maskLayer = [CALayer layer];    maskLayer.frame = ima.bounds;    UIImage *maskIamge = [UIImage imageNamed:@"1"];    maskLayer.contents = (__bridge id _Nullable)(maskIamge.CGImage);    temp.layer.mask = maskLayer;

Learning Animation Summary-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.