调用本地相册本地相机
访问本地相册
1 需要签两个协议 <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
2 创建UIImagePickerController来访问相册UIImagePickerController *picker = [[UIImagePickerController alloc] init];
3 签代理 picker.delegate = self;
4 picker.allowsEditing = YES; 然后允许进行编辑
5 进行跳转 [self presentViewController:picker animated:YES completion:^{}];
6 在- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法中获取图片
7 UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 从字典里提取info里的图片内容
8 self.imageView.image= image; 把图片赋给UIImageView
9 用户交互一定要打开 self.imageView.userInteractionEnabled=YES;
访问本地相机
1 UIImagePickerControllerSourceTypetype =UIImagePickerControllerSourceTypeCamera; 先把SourceType设置为相机
2 type =UIImagePickerControllerSourceTypeCamera; 照相机
3 sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 保存的相片
4 创建UIImagePickerController UIImagePickerController *picker = [[UIImagePickerController alloc] init];
5 签代理 picker.delegate = self;
6 picker.allowsEditing = YES; 设置可编辑
7 picker.sourceType = sourceType;
8 [self presentModalViewController:picker animated:YES]; 进入照相界面