One:
Specific use of the details, I also refer to http://blog.163.com/wkyuyang_001/blog/static/10802122820133190545227/
The following describes the use of Quartz 2D drawing to implement the drawing board function
In the. m file, the implementation of the dog is the same as shown in the connection
<pre name= "code" class= "OBJC" > #import "drawTestView.h" #import "Dog.h" @implementation drawtestview@synthesize dogs,tempdogs;-(nsmutablearray*) dogs{if (dogs = = nil) {dogs = [nsmutablearray array]; } return dogs;} -(nsmutablearray*) tempdogs{if (tempdogs = = nil) {tempdogs = [Nsmutablearray array]; } return tempdogs;} -(void) DrawRect: (cgrect) rect{cgcontextref ctx = Uigraphicsgetcurrentcontext (); Cgcontextsetfillcolorwithcolor (Ctx,[[uicolor Greencolor] cgcolor]); drawing board features [dogs enumerateobjectsusingblock:^ (id obj, Nsuinteger idx, BOOL *stop) {Nsmutablearray*arr = [dogs objec TATINDEX:IDX]; for (int i = 0; I<[arr count]; i++) {Dog*dog = (dog*) [arr objectatindex:i]; if (i = = 0) {cgcontextmovetopoint (CTX, dog.x, DOG.Y); }else{Cgcontextaddlinetopoint (CTX, dog.x, DOG.Y); } } }]; [[Uicolor Blackcolor]setstroKE]; Cgcontextdrawpath (CTX, Kcgpathstroke); }-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{Uitouch*touch = [touches anyobject]; Cgpoint location = [Touch locationinview:self]; Dog*dog = [[Dog alloc]init]; dog.x = location.x; Dog.y = LOCATION.Y; [Self.tempdogs Addobject:dog]; [Self.dogs AddObject:self.tempdogs]; [Self setneedsdisplay];//Call draw method}-(void) touchesmoved: (Nsset *) touches withevent: (uievent *) event{Uitouch*tou CH = [touches anyobject]; Cgpoint location = [Touch locationinview:self]; Dog*dog = [[Dog alloc]init]; dog.x = location.x; Dog.y = LOCATION.Y; [Self.tempdogs Addobject:dog]; [Self.dogs addobject:[self.tempdogs Copy]]; [Self setneedsdisplay];//Call draw method}-(void) touchesended: (Nsset *) touches withevent: (uievent *) event{[tempdogs Remov Eallobjects];}
Second: The use of the camera
To implement in the Viewcontroller used
< uinavigationcontrollerdelegate , uiimagepickercontrollerdelegate >//If you write only one uiimagepickercontrollerdelegate, a warning will appear, and you will not even invoke the proxy method
Imagepicker = [[Uiimagepickercontroller alloc]init]; Imagepicker.delegate = self;
How to get into the camera
-(Ibaction) Goimagepicker: (ID) Sender { if ([Uiimagepickercontroller issourcetypeavailable: Uiimagepickercontrollersourcetypecamera]) { Self.imagePicker.sourceType = Uiimagepickercontrollersourcetypecamera; Self.imagePicker.cameraDevice = uiimagepickercontrollercameradevicefront;//invokes the front-facing header }else{ Self.imagePicker.sourceType = uiimagepickercontrollersourcetypephotolibrary; } self.imagePicker.allowsEditing = YES; [Self PresentViewController:self.imagePicker animated:yes completion:nil];}
Implement two proxy methods:
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info { NSLog (@ "select"); UIImage * image = [info objectforkey:uiimagepickercontrollereditedimage]; _imageselect.frame = CGRectMake (_imageselect.frame.origin.x, _IMAGESELECT.FRAME.ORIGIN.Y, _ ImageSelect.frame.size.width, _imageselect.frame.size.width*image.size.height/image.size.width);//In order not to distort the selected picture _imageselect.image = image; [Self.imagepicker Dismissviewcontrolleranimated:yes completion:nil];} -(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{ [Self.imagepicker Dismissviewcontrolleranimated:yes Completion:nil];}
iOS (Quartz 2D Drawing) Various drawing methods and the use of cameras