iOS之相册实现
2016-02-22 10:19
381 查看
代码演示:
- (IBAction)btAction:(UIButton *)sender { //创建提示框 控制器 UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示框" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; //创建相机的点击事件按钮 UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action){ //判断系统设备是否存在相机,有调用 没有提醒用户 if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { //如果有摄像头 ,创建相机 UIImagePickerController *picker = [[ UIImagePickerController alloc] init]; //指定数据来源,来自于相机 picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.delegate = self; picker.allowsEditing = YES;//允许编辑 //使用模态弹出相机 [self presentViewController:picker animated:YES completion:nil]; }else { //没有摄像头提醒用户,您的设备没有摄像头 UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"您的设备没有摄像头" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]; [controller addAction:action]; [self presentViewController:controller animated:YES completion:nil]; } }]; [alertC addAction:alertA];//添加到提示框 //创建相册的点击事件按钮, UIAlertAction *action = [ UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){ UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//指定数据来源是相册 picker.delegate = self; picker.allowsEditing = YES; [self presentViewController:picker animated:YES completion:nil]; }]; [alertC addAction:action]; [self presentViewController:alertC animated:YES completion:nil]; } //选取图片之后执行的方法 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ NSLog(@"%@",info);//是个字典 //通过字典的key值来找到图片 UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];//并且赋值给声明好的imageView self.imageView.image = image; //最后模态返回 最初的 控制器 [picker dismissViewControllerAnimated:YES completion:nil]; }
相关文章推荐
- iOS 取消tableviewcell 点击效果
- 第三方框架Cocoapod使用
- IOS开发过程常见警告解决方案归纳总结
- 2016年 iOS春节后证书无效
- Direct iCloud Access and iOS 9.3 Support
- iOS 检测内存泄漏Analyze出现的一些问题
- iOS LaunchImage 标准尺寸
- iostat 命令
- ios开发(三方集成)--ShareSDK常见问题汇总
- iOS/OS X 内存管理(二):借助工具解决内存问题
- iOS学习笔记(十四)——打电话、发短信
- iOS购物分类模块的实现方案
- iOS开发-------初探运行时runtime
- iOS横屏问题
- IOSCategory类别和Extension扩展
- 高德地图SDK开发(IOS版本)
- IOS 聊天界面Demo
- IOS视频播放器(改自36Kr开源的KRVideoPlayer)
- 原生IOS 7.0 SDK AVF 包实现的二维码扫描
- IOS开发中的小问题整理,持续更新(小问题,大麻烦)