iOS开发——打开手机相册,获取图片
1.添加代理UIImagePickerControllerDelegate
2.设置点击跳转事件
- (IBAction)picButton:(UIButton *)sender {
NSLog(@"我的相册");
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
//a.初始化相册拾取器
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
//b.设置代理
controller.delegate = self;
//c.设置资源:
/**
UIImagePickerControllerSourceTypePhotoLibrary,相册
UIImagePickerControllerSourceTypeCamera,相机
UIImagePickerControllerSourceTypeSavedPhotosAlbum,照片库
*/
controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//d.随便给他一个转场动画
controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:NULL];
}else{
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"设备不支持访问相册,请在设置->隐私->照片中进行设置!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}
}
3.获取图片
#pragma mark-> imagePickerController delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//a.获取选择的图片
UIImage *image = info[UIImagePickerControllerOriginalImage];
self.imageView.image = image;
}
最新文章
- 抽象工厂模式(Abstract Factory Pattern)
- 【转】ORACLE定期清理INACTIVE会话
- Libcurl多线程crash问题(cento)
- ue4 模块的构建和加载
- Enum:Backward Digit Sums(POJ 3187)
- Girls: different perspectives to consider
- 上海洋码头(www.ymatou.com)急招技术人才(职位:互联网软件开发工程师,.NET网站架构师,Web前端开发工程师,高级测试工程师,产品经理)
- ubuntu启动失败the system is running in low graphics mode
- hdu 4652 Dice 概率DP
- MongoDB命令行操作
- 某APK中使用了动态注册BroadcastReceiver,Launcher中动态加载此APK出现java.lang.SecurityException异常的解决方法
- Servlet页面间对象传递的方法
- 【JSONKit】序列化Dictionary崩溃
- smarty如何处理状态值的显示
- poj3177(边双连通分量+缩点)
- CRtmpServer分析与应用
- CentOS7 安装Nginx+MySQL
- Mysql数据库使用量查询及授权
- nginx 系列 1 linux下安装以及配置IIS分发
- 【学习】数据处理基础知识(基本功能)【pandas】