Layer and 3D affine transformations

Source: Internet
Author: User

1. The view's display is based on a layer, which also controls the display, gets the layer of the current view, and adds rounded borders to it.
  Sets the width of the layer border to 2  view.layer.borderwidth=2;   If you need to add a color to a layer you need to convert to Cgcolor object   View.layer.bordercolor=[uicolor Greencolor]. Cgcolor;  Sets the fillet radius of the border to   view.layer.cornerradius=10;
2. Set the shadow of the view through the layer
    1 Set the current shadow color    view.layer.shadowcolor=[uicolor Blackcolor]. Cgcolor;    2 Set the current convex shadow, through this method to control the extent of the current shadow convex, so as to achieve the desired effect    view.layer.shadowoffset=cgsizemake (5, 5);    3 Set the current transparency view.layer.shadowopacity=0.5;
3. Custom Layer
    Calayer *layer=[calayer layer];    Layer.bordercolor=[uicolor Redcolor]. Cgcolor;    layer.borderwidth=2;    layer.cornerradius=10;    Layer.backgroundcolor=[uicolor Redcolor]. Cgcolor;layer.bounds=cgrectmake (0, 0, Max, +);   Set position control the current position layer.position=cgpointmake (100, 100);//Set the anchor point to control the position of the position, the size of the anchor point is 0-1, it can be understood to be proportional to the location of the position point of the layer, Position the point to the position indicated by the Position property so that you can control the position of the current layer with two properties Layer.anchorpoint=cgpointmake (0, 0);//Add the current layer to the currently displayed layer    [ Self.view.layer Addsublayer:layer];
4. Layer 3D affine transform

  1. Panning

  1.1, 3D translation is divided into x Y Z three-dimensional, set the value will be set in the direction of translation

T1:x axis offset position, down to positive.

T2:y axis offset position, positive to right.

T3:z the axis offset position, and a positive number outward.

Nsvalue * Nav=[nsvalue valuewithcatransform3d:catransform3dmaketranslation (t1, T2, T3)]; [View.layer setvalue:nav forkey:@ "transform"];

  1.2, through the KVC assignment, as shown in the table below

Pan 100[view.layersetvalue:@ (+) forkeypath:@ "transform.translation.x"];//along the X-direction to pan in the y direction 100[view.layersetvalue:@ (+) forkeypath:@ "TRANSFORM.TRANSLATION.Y"];//shift in z direction 100[view.layersetvalue:@ (+) forkeypath:@ " Transform.translation.z "];

  2. Rotation

2.1, rotation has four parameters, the first is the angle of rotation, in radians, the following three values correspond to three axes, you can set rotation around different axes

X: Rotates along the x-axis, with a value range between 1 and 1

Y: Rotates along the y-axis, with a value range between 1 and 1

Z: Rotates along the z-axis, with a value range between 1 and 1

    [UIView animatewithduration:1 animations:^{       view.layer.transform=catransform3dmakerotation (M_PI, 0, 0,-1);    }];

2.2, through the KVC assignment value

Rotate along the z axis [view.layer setvalue:@ (m_pi_2) forkeypath:@ "transform.rotation.z"];//rotate along the x axis [View.layer setvalue:@ (M_PI_2) forkeypath:@ "Transform.rotation.x"];

  3. Zoom

3.1, three parameters are scaled along each axis in multiples, sequentially X Y z three-dimensional.

View.layer.transform=catransform3dmakescale (1, 1.5, 1);

3.2, through the KVC assignment value

Enlarge 1.5 times times along the x-axis [View.layer setvalue:@ (1.5) forkeypath:@ "transform.scale.x"];//1.5 times times more along the y-axis [View.layer setvalue:@ (1.5) forkeypath:@ "Transform.scale.y"];//magnified 1.5 times times along the z-axis [view.layer setvalue:@ (1.5) forkeypath:@ "Transform.scale.z" ];

Layer and 3D affine transformations

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.