ios UIImagePickerController简单说明
首先,VC中添加#import <MobileCoreServices/MobileCoreServices.h> 使用(NSString *) kUTTypeImage定义在其中
判断是否授权:
NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
AVAuthorizationStatusNotDetermined = 0,//未明确
AVAuthorizationStatusRestricted,//受限
AVAuthorizationStatusDenied,//不允许
AVAuthorizationStatusAuthorized//允许
第一种使方法照相机:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//添加代理
imagePicker.delegate = self;
//是否允许编辑
imagePicker.allowsEditing = YES;
//资源类型
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//media类型
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil];
//转跳
[self presentModalViewController:imagePicker animated:YES];
第二种使用摄像机:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//media类型
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
//视频品质
imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow;
[self presentModalViewController:imagePicker animated:YES];
第三种使用相册取图片类型:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeImage, nil];
[self presentModalViewController:imagePicker animated:YES];
第四种使用相册取视频类型:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentModalViewController:imagePicker animated:YES];
代理:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeImage]) {
//获取照片的原图
UIImage* original = [info objectForKey:UIImagePickerControllerOriginalImage];
//获取图片裁剪的图
UIImage* edit = [info objectForKey:UIImagePickerControllerEditedImage];
//获取图片裁剪后,剩下的图
UIImage* crop = [info objectForKey:UIImagePickerControllerCropRect];
//获取图片的url
NSURL* url = [info objectForKey:UIImagePickerControllerMediaURL];
//获取图片的metadata数据信息
NSDictionary* metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
//如果是拍照的照片,则需要手动保存到本地,系统不会自动保存拍照成功后的照片
// UIImageWriteToSavedPhotosAlbum(edit, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
} else if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) {
NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
self.fileData = [NSData dataWithContentsOfFile:videoPath];
}
[picker dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
ios UIImagePickerController简单说明的更多相关文章
- iOS上简单推送通知(Push Notification)的实现
iOS上简单推送通知(Push Notification)的实现 根据这篇很好的教程(http://www.raywenderlich.com/3443/apple-push-notification ...
- iOS CAReplicatorLayer 简单动画
代码地址如下:http://www.demodashi.com/demo/11601.html 写在最前面,最近在看学习的时候,偶然间发现一个没有用过的Layer,于是抽空研究了下,本来应该能提前记录 ...
- iOS之简单瀑布流的实现
iOS之简单瀑布流的实现 前言 超简单的瀑布流实现,这里说一下笔者的思路,详细代码在这里. 实现思路 collectionView能实现各中吊炸天的布局,其精髓就在于UICollectionVie ...
- iOS,手势识别简单使用
1.iOS目前支持的手势识别(6种) 2.点按手势和慢速拖动手势简单使用 iOS目前支持的手势识别(6种) UITapGestureRecognizer(点按) UIPinchGestureRecog ...
- iOS - UIImagePickerController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImagePickerController : UINavigationController <NSCod ...
- iOS NSData简单解析
iOS 基本数据类型之NSData 1 nsdata 作用: 用于存储二进制的数据类型 nadat类提供一种简单的方式,它用来设置缓存区.将文件的内容读入到缓存区.或者将缓存区中的内容写到一个文件. ...
- iOS 多线程 简单学习NSThread NSOperation GCD
1:首先简单介绍什么叫线程 可并发执行的,拥有最小系统资源,共享进程资源的基本调度单位. 共用堆,自有栈(官方资料说明iOS主线程栈大小为1M,其它线程为512K). 并发执行进度不可控,对非原子操作 ...
- iOS开发-简单工厂模式
设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性.概念很长,iOS开发中最常 ...
- ios label 简单的长按复制文本信息
在iOS开发过程中,有时候会用到UILabel展示的内容,那么就设计到点击UILabel复制它上面展示的内容的功能,也就是Label长按复制功能.网上有很多种给Label添加长按复制功能的方法,这里我 ...
随机推荐
- jquery的ajax提交后,会跳转页面
今天在写代码的时候,遇到一个很奇怪的问题,一个form表单,用的是ajax的方式提交.结果,在服务器端php中,使用exit(),函数后都不能停止,并且继续跳转到本页.请求如下: 第一个请求中,其实我 ...
- 数据的增删改查(三层)<!--待补充-->
进行数据操作必然少了对数据的增删改查,用代码生成器生成的代码不是那么满意!方便在今后使用,这里就主要写“数据访问层(Dal)” 既然这里提到三层架构:有必要将三层内容在这里详细介绍一下(待补充) 注: ...
- Ubuntu16.04下搭建LAMP环境
前期准备sudo apt-get update # 获取最新资源包sudo apt-get upgrade # 本机软件全部更新sudo apt-get d ...
- 软件测试之fault、error和failure的理解
(1) Identify the fault : The first element of the array is not looped. "for(int i=x.length-1;i ...
- 1179: [Apio2009]Atm
1179: [Apio2009]Atm Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 1629 Solved: 615[Submit][Status ...
- ReactJS React+Redux+Router+antDesign通用高效率开发模板,夜间模式为例
工作比较忙,一直没有时间总结下最近学习的一些东西,为了方便前端开发,我使用React+Redux+Router+antDesign总结了一个通用的模板,这个技术栈在前端开发者中是非常常见的. 总的来说 ...
- css 超出隐藏显示...
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- Markdown语法讲解及MWeb使用教程
写了一个月的博客,忽然感觉Markdown编辑器比较好用,于是就下载了一个本地的Markdown编辑软件学习了一下,刚好软件里自带了一篇英文的指示文档,顺便翻译了一下,通过这个过程也大致熟悉了Mark ...
- jsp想js,action传值
1.struts2 action如何向JSP的JS函数传值 action中定义变量 public class TestAction extends ActionSupport implements S ...
- 【转】Lucene.NET详细使用与优化详解
1 lucene简介1.1 什么是luceneLucene是一个全文搜索框架,而不是应用产品.因此它并不像www.baidu.com 或者google Desktop那么拿来就能用,它只是提供了一种工 ...