打开相机:
- UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
-
-
-
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.allowsEditing = YES;
- picker.sourceType = sourceType;
- [self presentModalViewController:picker animated:YES];
- [picker release];
打开相册:(区分pad和iphone)
for iphone:
- UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
- if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
- pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
-
- pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
-
- }
- pickerImage.delegate = self;
- pickerImage.allowsEditing = NO;
- [self presentModalViewController:pickerImage animated:YES];
- [pickerImage release];
for ipad:
- UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
-
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.allowsEditing = NO;
- picker.sourceType = sourceType;
-
-
- UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:picker];
- self.imagePicker = popover;
-
- [self.imagePicker presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- [picker release];
- [popover release];
点击相册中的图片 货照相机照完后点击use 后触发的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary
*)info
点击cancel 调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
例子下载地址:http://download.csdn.net/download/like7xiaoben/4958356
本文转自......
IOS成长之路-调用照相机和相册功能,布布扣,bubuko.com
IOS成长之路-调用照相机和相册功能
原文:http://www.cnblogs.com/wlcc/p/3906805.html