iOS drawing, screenshots and emptying

Source: Internet
Author: User

1 #import "ViewController.h"2 #import "SecondVC.h"3 4 5 #defineWIDTH [UIScreen mainscreen].bounds.size.width6 #defineHEIGHT [UIScreen mainscreen].bounds.size.height7 8 @interfaceViewcontroller ()9 {TenUiimageview *_canvasview;//Canvas OneCgpoint _startpoint;//Record start coordinates A      - } - @end the  - @implementationViewcontroller -  -- (void) Viewdidload { + [Super Viewdidload]; -      +_canvasview =[[Uiimageview alloc] initWithFrame:self.view.bounds]; A [Self.view Addsubview:_canvasview]; at      -UIButton *clearbtn =[UIButton Buttonwithtype:uibuttontypecustom]; -Clearbtn.frame = CGRectMake ( -, -, -, -); - [clearbtn addtarget:self Action: @selector (Clearbtnclick) forcontrolevents:uicontroleventtouchupinside]; -[Clearbtn Settitle:@"Clear"Forstate:uicontrolstatenormal]; -Clearbtn.backgroundcolor =[Uicolor Orangecolor]; in [Self.view addsubview:clearbtn]; -      toUIButton *cutpicbtn =[UIButton Buttonwithtype:uibuttontypecustom]; +Cutpicbtn.frame = CGRectMake ( -, -, -, -); - [cutpicbtn addtarget:self Action: @selector (Cutpicbtnclick) forcontrolevents:uicontroleventtouchupinside]; the[Cutpicbtn Settitle:@""Forstate:uicontrolstatenormal]; *Cutpicbtn.backgroundcolor =[Uicolor Orangecolor]; $ [Self.view addsubview:cutpicbtn];Panax Notoginseng      - } the  +  A- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event the { +_startpoint =[[Touches Anyobject] locationinview:_canvasview]; -  $ } $  -- (void) touchesmoved: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event - { theCgpoint Movepoint =[[Touches Anyobject] locationinview:_canvasview]; - Wuyi //There are a lot of moving points, the @autoreleasepool { -Uigraphicsbeginimagecontext (Cgsizemake (WIDTH, HEIGHT));//start a drawing of a picture Wu          -[_canvasview Drawrect:_canvasview.frame];//draw lines that already exist About          $Cgcontextref context = Uigraphicsgetcurrentcontext ();//drawing buffer, current is a picture -Cgcontextsetlinewidth (Context,5); -Cgcontextsetrgbstrokecolor (Context,1,0,0,1); -Cgcontextsetlinecap (context, kcglinecapround);//Side Caps ACgcontextsetlinejoin (context, kcglinejoinround);//suture +          the cgcontextmovetopoint (context, _startpoint.x, _startpoint.y); - cgcontextaddlinetopoint (context, movepoint.x, movepoint.y); $ Cgcontextstrokepath (context); the_canvasview.image = Uigraphicsgetimagefromcurrentimagecontext ();//gets the picture in the current picture drawing area the          theUigraphicsendimagecontext ();//Close Picture Drawing the     } -      in_startpoint =Movepoint; the } the  About  the #pragmaMark-Clear Button the- (void) Clearbtnclick the { +      -_canvasview.image =Nil; the     Bayi } the  the #pragmaMark-Cut button -- (void) Cutpicbtnclick - { theUigraphicsbeginimagecontext (Cgsizemake (WIDTH, HEIGHT));//start a drawing of a picture the //after the screen loads the [Self.view drawViewHierarchyInRect:self.view.frame afterscreenupdates:yes]; the      -UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();//gets the picture in the current picture drawing area the      the Uigraphicsendimagecontext (); the     94SECONDVC *VC =[[SECONDVC alloc] init]; theVc.image =image; the [self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil]; the}

iOS drawing, and emptying

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.