Layer and 3D affine transform, layer3d imitation

Source: Internet
Author: User

Layer and 3D affine transform, layer3d imitation
1. View display is based on a layer. You can control the display effect by using the control layer to obtain the layer of the current view and add a rounded border to it.

// Set the width of the layer border to 2 view. layer. borderWidth = 2; // if you want to add a color for the layer, You need to convert it to the CGColor object view. layer. borderColor = [UIColor greenColor]. CGColor; // set the rounded corner radius of the border to 10 views. layer. cornerRadius = 10;
2. Set the view shadow through layer
// 1. Set the current shadow color view. layer. shadowColor = [UIColor blackColor]. CGColor; // 2 sets the currently convex shadow. This method is used to control the degree of the current convex shadow to achieve the desired effect view. layer. shadowOffset = CGSizeMake (5, 5); // 3 sets 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,200,100); // sets position to control the current position layer. position = CGPointMake (100,100); // set the position of the anchor to control the position. The size range of the anchor is 0-1. It can be understood that the position of the layer is located proportionally, position the point to the position indicated by the position attribute, so that the position layer of the current layer can be well controlled through the two attributes. anchorPoint = CGPointMake (0, 0); // Add the current layer to the currently displayed layer [self. view. layer addSublayer: layer];
4. layer 3D Affine Transformation

  1. Translation

  1.1 3D translation is divided into x y z 3D, and the values are set to pan along the set direction.

T1: the position at which the X axis is offset. The value is positive.

T2: Y-axis offset, positive to the right.

T3: The Z axis offset position, which is a positive number.

NSValue * nav=[NSValue valueWithCATransform3D: CATransform3DMakeTranslation(t1, t2, t3)];[view.layer setValue:nav forKey:@"transform"];

  1.2 assign values using KVC, as shown in the following table.

 

// Translate 100 [view. layersetValue: @ (100) forKeyPath: @ "transform. translation. x "]; // Pan 100 [view. layersetValue: @ (100) forKeyPath: @ "transform. translation. y "]; // translate 100 [view. layersetValue: @ (100) forKeyPath: @ "transform. translation. z "];

  2. Rotate

2.1. There are four parameters for rotation. The first one is the rotation angle, expressed in radians. The last three values correspond to three axes respectively. You can set the rotation around different axes.

X: rotate along the x axis. The value ranges from-1 to 1.

Y: rotate along the y axis. The value ranges from-1 to 1.

Z: rotate along the z axis. The value ranges from-1 to 1.

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

2.2 assign values through KVC

// Rotate [view. layer setValue: @ (M_PI_2) forKeyPath: @ "transform. rotation. z "]; // rotate [view. layer setValue: @ (M_PI_2) forKeyPath: @ "transform. rotation. x "];

3. Zoom

3.1. The three parameters are the multiples of scaling along each axis, and the order is x y z 3D.

view.layer.transform=CATransform3DMakeScale(1, 1.5, 1);

3.2 assign values through KVC

// Zoom in multiple [view. layer setValue: @ (1.5) forKeyPath: @ "transform. scale. x "]; // zoom in multiple [view. layer setValue: @ (1.5) forKeyPath: @ "transform. scale. y "]; // zoom in multiple [view. layer setValue: @ (1.5) forKeyPath: @ "transform. scale. z "];

 

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.