iOS Development UI Chapter-quartz2d use (Matrix operations)

Source: Internet
Author: User

In front of the drawing of basic graphics, the four-sided shape is composed of a few straight lines, now there is a more convenient method.

first, about the matrix operation 1. Draw a quadrilateralA four-sided drawing is done by setting two endpoints (length and width). Code:View CodeDescription: Drawing rectangles In this way has weaknesses: the drawn rectangles are always squares. such as: How to draw a crooked rectangle? (Done with a matrix operation, similar to a deformation operation) can be manipulated by the matrix to deform (rotate, scale, pan) the drawing of Things: CGCONTEXTROTATECTM (< #CGContextRef C#>, < #CGFloat Angle#>) This accepts two parameters (graphics context, radians) Note: Setting the matrix operation must be done before adding a graphic, if it is finished after adding a graphic, it is not valid. Code:View CodeEffect: Two, about rotation 1. Rotate the demo view to display the view because it has a layer on it, and the future graph is rendered to the layer. And, when rotating the entire layer is rotated, you can draw a circle to verify. Code 1 (not rotated):View CodeEffect: Code 2 (rotation):View Code

Effect:

2. Additional instructions on rotation tip: When rotating, the entire layer is rotated. Three, scaling method: Cgcontextscalectm (< #CGContextRef C#>, < #CGFloat Sx#>, < #CGFloat sy#>) The method receives three parameters (the graphics context, Scaling in the x direction, example of scaling code in the y direction:View Code

Effect:

Four, translation method: Cgcontexttranslatectm (< #CGContextRef C#>, < #CGFloat Tx#>, < #CGFloat ty#>) The method receives three parameters (the graphics context, X-direction offset, offset in Y-direction) code example:View Code

Effect:

Tip: The coordinate origin is the upper-left corner of the view.

iOS Development UI Chapter-quartz2d use (Matrix operations)

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.