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