本文讲述如何进入系统的照片或者照相机
1.创建一个照片选择控制器
UIImagePickerController *imagePickerVc = [[UIImagePickerController alloc] init];
2.设置数据源(弹出的是否直接是照片库)
imagePickerVc.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
3.设置代理(UIImagePickerControllerDelegate)
imagePickerVc.delegate = self;
4.把图片库Modal出来
[self presentViewController:imagePickerVc animated:YES completion:nil];
如何监听并处理弹出来照片库的点击事件?
1.遵守代理协议
@interface ViewController ()< UIImagePickerControllerDelegate>
2.设置代理为self
imagePickerVc.delegate = self;
3.实现代理方法
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
//获取用户选择照片
UIImage*image = info[UIImagePickerControllerOriginalImage];
//把Modal出来的imagePickerController弹出
[selfdismissViewControllerAnimated:YEScompletion:nil];
//在此处理图片,赋值
}
网友评论