iOS 相机工具类
来源:互联网 发布:mac safari缓存文件 编辑:程序博客网 时间:2024/06/05 17:51
最近优化一些项目,然后就简单的把调用系统相机封装了一下。
1 首先需要申请权限
2 跳转到UIImagePickerController的代码
+(ImagePickerManager *)shareManager{ static ImagePickerManager *instance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ instance = [[ImagePickerManager alloc] init]; }); return instance;}-(void)showImagePickFromAllowsEditing:(BOOL)allowsEditing videoQuality:(UIImagePickerControllerQualityType)videoQuality sourceType:(UIImagePickerControllerSourceType)sourceType modalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle controller:(UIViewController *)vc completion:(completionBlock)completion{ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; //可以编辑 picker.allowsEditing = allowsEditing; //设置图片质量 picker.videoQuality=videoQuality; picker.sourceType = sourceType; picker.modalPresentationStyle = modalPresentationStyle; _vc = vc; _comBlock = [completion copy]; [_vc presentViewController:picker animated:YES completion:^{ }]; }else{ if (_comBlock) { _comBlock(@"不支持拍照",nil); } }}
3 取消
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [_vc dismissViewControllerAnimated:YES completion:^{ }];}
4 确定图片之后的回调
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ //设置为常规的图片 UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage]; //主线程等待0.5秒回到根视图 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.51 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (![_vc.presentedViewController isBeingDismissed]) { [_vc dismissViewControllerAnimated:YES completion:^{ }]; } }); if (_comBlock) { _comBlock(nil,img); }}
5 使用
[[ImagePickerManager shareManager] showImagePickFromAllowsEditing:YES videoQuality:UIImagePickerControllerQualityTypeLow sourceType:UIImagePickerControllerSourceTypeCamera modalPresentationStyle:UIModalPresentationOverCurrentContext controller:self completion:^(NSString *msg, UIImage *img) { if (msg) { NSLog(@"%@",msg); } if (img) { [self showImage:img]; } }];
Demo http://download.csdn.net/detail/rpf2014/9704191
0 0
- iOS 相机工具类
- 相机相关工具类
- iOS获取系统相册、相机、麦克风权限的工具
- 处理系统相机、相册图片工具类
- IOS之相机全屏
- iOS调用相机详解
- iOS相机去黑框
- iOS 相机手动对焦
- iOS 相机调用
- iOS开发-调用相机
- ios相机和图片
- iOS AVcapture 自定义相机
- iOS 相册 相机
- iOS自定义相机
- iOS自定义相机界面
- iOS 访问相机 相册
- iOS 打开相机、相册
- iOS相机选择器
- VSCode快捷键设置
- javascript事件——event对象
- 反转链表
- HTTPS原理
- Android 反编译初探 应用是如何被注入广告的
- iOS 相机工具类
- Java之--Stack栈
- 教你手机号码批量查询归属地的方法
- 算法练习2:Two fighters, one winner.
- 引入其他字体库 和 字体样式设置
- jQuery的图片轮播插件PgwSlideshow使用详解
- linux命令大全——系统管理(二)
- Bootstrap(1)
- 快速教你使用CSDN-markdown编辑器