您的位置:首页 > 其它

打开系统相册/相机,选择图片

2015-09-17 20:42 344 查看
1.实现2个代理<UINavigationControllerDelegate,UIImagePickerControllerDelegate>

2.
/**
*  打开相机
*/
- (void)openCamera
{
UIImagePickerController *pic = [[UIImagePickerController alloc] init];
pic.sourceType = UIImagePickerControllerSourceTypeCamera;
pic.delegate = self;
[self presentViewController:pic animated:YES completion:nil];
}

/**
*  打开相册
*/
- (void)openPhotoLibrary
{
UIImagePickerController *pic = [[UIImagePickerController alloc] init];
pic.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pic.delegate = self;
[self presentViewController:pic animated:YES completion:nil];
}

#pragma mark - 图片选中控制器的代理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//1.销毁picker控制器
[picker dismissViewControllerAnimated:YES completion:nil];

//2.取得图片
UIImage *image = info[UIImagePickerControllerOriginalImage];
self.imageView.image = image;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: