Summary of simple strokes project: IOS Drawing Mechanism & recording handwriting function iPhone: Coordinate Transformation iPhone: animation effects similar to drawsomething

Source: Internet
Author: User

The simplified strokes project started in March August of the summer and has been published in more than September. The project can be completed only after the modification and modification. now it's a little late, and I forget some experiences, but I still try my best to record what I think is useful. 

1,Storyboards. Summary of my previous project: summary of the android client for Development and Education on the campus of South China Normal UniversityThe story board is the design of the project. Because the project system is complex and the logic consistency is not strong, this tests the ability of the storyboard designers to write storyboards. In fact, the story board is what you need to fully understand the entire application dependencies, so if the story board is clearly and reasonably written, the project will go smoothly. Many details of this story board have not been clearly explained. Many things need to be discussed later to be finalized. Although this is inevitable, it can be reduced.

2,IOS plotting Mechanism: Because the simple strokes project is mainly a drawing software, it is necessary to summarize some iOS drawings.

Https://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html#//apple_ref/doc/uid/TP40010156-CH14-SW1

Refer to the official documents above.

IOS provides two plotting schemes:

1. iOS core Graphics Library:Quartz, core animation, and uikit

2. OpenGL ES is used.

This project is the first one. OpenGL is more applied to game scenarios.

The quartz class library is the main class library for painting. It provides operations based on path drawing, anti-sawtooth rendering, gradient filling, image, color, coordinate space conversion, and PDF documentation.

Uikit provides dashes,Objecz images and the objective-C encapsulation of color operations.

Core Animation: ProvidesThe underlying support of uikit can also be used to implement Custom Animation.

 

The uikit Graphics System

1. drawing is mainly carried out in drawrect:, but you cannot actively call it. It can only be called by the system itself.SetneedsdisplayOrSetneedsdisplayinrect:Notify the system to update the drawing. The system then calls drawrect.

2,Graphics contexts:Conceptually, a graphics context is an object that describes where and how drawing shocould occur, including basic drawing attributes such as the colors to use when drawing, the clipping area, line width and style information, font information, compositing options, and so on. From the definition, we can see that,Graphics contexts can be understood as a drawing board, which can define some basic drawing elements. Each uiview is created.

3. Coordinates.

Is the relationship between user coordinates, View coordinates, and hardware coordinates. But we are more concerned with the coordinate system provided by the IOS interface: Two Coordinate Systems

Upper-left-origin coordinate system (UlO) andLower-left-origin coordinate system (llo)

For details about coordinate transformation, referIPhone: coordinate transformation.

4. Drawing.

After talking about this, how can we achieve drawing on iOS?

 

-( Void  ) Drawrect :( cgrect) rect {cgcontextref  Ref = Uigraphicsgetcurrentcontext (); //  Obtain the prepared canvas. The drawing on this canvas is to draw on the current view. Cgcontextbeginpath ( Ref );//  A very important concept mentioned here is path, which is actually to tell the canvas environment that we are about to start painting. You can write it down. Cgcontextmovetopoint ( Ref , 0 , 0 ); //  Do I need to explain how to draw a line? No, right? It is two points to determine a straight line. Cgcontextaddlinetopoint ( Ref , 300 , 300  ); Cgfloat redcolor [  4 ] = { 1.0 ,0 , 0 , 1.0  }; Cgcontextsetstrokecolor (  Ref , Redcolor ); //  Set the color of the current paint brush. Cgcontextstrokepath ( Ref ); //  Tell the canvas to paint the path I moved with a paint brush. }

 

There are several steps to draw a line easily:

1. Obtain the uigraphicsgetcurrentcontext of the current Panel.

2. Start to draw a statement.

3. Painting

4. Submit the painting

Mainly inThe changes made by graphics contexts are as follows:

 

For details, refer to the document here.

5. View

 
-(Uiimage *) Getimage {uigraphicsbeginimagecontext (self. bounds. size); [self. layer renderincontext: uigraphicsgetcurrentcontext ()]; uiimage* IMG =Uigraphicsgetimagefromcurrentimagecontext (); uigraphicsendimagecontext ();ReturnIMG ;}

 

 Recorded handwriting:

View my other blog:IPhone: Implements animation effects similar to drawsomething for automatic drawing.

 

 

 

More: http://iosdeveloper.diandian.com/post/2011-12-29/16946271

 

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.