Ios (Quartz 2D drawing) Various plotting methods and camera usage, iosquartz
I:
Specific use details, I am also a reference http://blog.163.com/wkyuyang_001/blog/static/10802122820133190545227/
The following describes how to use Quartz 2D drawing to implement the graphic board function.
In the. m file, dog is implemented 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]); // graphic board function [dogs Background: ^ (id obj, NSUInteger idx, BOOL * stop) {NSMutableArray * arr = [dogs objectAtIndex: 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 the draw method}-(void) touchesMoved :( 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 copy]; [self setNeedsDisplay]; // call the draw method}-(void) touchesEnded :( NSSet *) touches withEvent :( UIEvent *) event {[tempdogs removeAllObjects];}
Ii. Use of cameras
To be implemented in the viewcontroller in use
<UINavigationControllerDelegate, UIImagePickerControllerDelegate> // if you write only one UIImagePickerControllerDelegate, a warning is reported, or even a proxy method is not called.
imagePicker = [[UIImagePickerController alloc]init]; imagePicker.delegate = self;
How to enter the camera
-(IBAction) goImagePicker :( id) sender {if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {self. imagePicker. sourceType = UIImagePickerControllerSourceTypeCamera; self. imagePicker. cameraDevice = UIImagePickerControllerCameraDeviceFront; // call the front image 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: alias]; _ 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); // to Prevent Deformation of the selected image _ imageSelect. image = image; [self. imagePicker dismissViewControllerAnimated: YES completion: nil];}-(void) imagePickerControllerDidCancel :( UIImagePickerController *) picker {[self. imagePicker dismissViewControllerAnimated: YES completion: nil];}