YouTip LogoYouTip

Ios Camera

# iOS Camera Management * * * ## Introduction to Camera One of the common features of mobile devices is the camera. We can use the camera to take pictures and integrate it into our applications, and using the camera is quite simple. ### Example Steps 1. Create a simple View-based application 2. Add a button (button) in ViewController.xib, and create an IBAction for this button 3. Add an image view (image view), and create an IBOutlet named imageView 4. The code in ViewController.h is as follows: ```objc #import @interface ViewController : UIViewController{ UIImagePickerController *imagePicker; IBOutlet UIImageView *imageView; } - (IBAction)showCamera:(id)sender; @end 5. Modify ViewController.m as shown below: ```objc #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { ; } - (void)didReceiveMemoryWarning { ; // Dispose of any resources that can be recreated. } - (IBAction)showCamera:(id)sender { imagePicker.allowsEditing = YES; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; } else { imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; } [self presentModalViewController:imagePicker animated:YES]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; if (image == nil) { image = [info objectForKey:UIImagePickerControllerOriginalImage]; } imageView.image = image; } -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissModalViewControllerAnimated:YES]; } @end
← Ios LocationIos Universal Applications β†’