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添加长按复制功能的方法,这里我 ...
随机推荐
- Android学习总结——开篇
不知不觉做Android开发已经2年多了,一直都没有好好总结过Android的相关内容,是时候好好总结和梳理一下Android的相关内容了,就从最基本的Activity开始吧,关于Activity的知 ...
- Android Http请求头与响应头的学习
本节引言: 上节中我们对Android涉及的网络编程进行了了解,也学习了下Http的基本概念,而本节我们 要学习的是Http的请求头与响应头,当然,可以把也可以把这节看作文档,用到的时候来查查 即可! ...
- Cloud9vue&vux上传github小步骤
成功后创建出以下文件,再输入: git init 再输入:$ git remote add origin https://github.com/github用户名/vux1 然后:git add. 按 ...
- MySQL基础语句与其在Python中的使用
一.MySQL基础语句 $ mysql -u root -p (有密码时) $ mysql -u root (无密码时) QUIT (or \q) 退出 查看当前所有数据库 show dat ...
- Visual Studio 2017正式版离线安装及介绍
Visual Studio 2017 RTM正式版离线安装及介绍. 首先至官网下载:https://www.visualstudio.com/zh-hans/downloads/ VS 2017 正式 ...
- 香港多IP站群服务器-搭建多IP代理服务器、游戏加速服务器
耀磊花楹qq82521463香港WK自营机房多IP服务器租用,多IP站群服务器,多IP多C段 站群服务器租用 耀磊数据拥有3万个自由香港IP以及独立AS号,是APNIC核心成员,机房通过BGP融合 多 ...
- Source Map入门教程
部署前端之前,开发者通常会对代码进行打包压缩,这样可以减少代码大小,从而有效提高访问速度.然而,压缩代码的报错信息是很难Debug的,因为它的行号和列号已经失真.这时就需要Source Map来还原真 ...
- swift -- 代理delegate
1.声明协议 protocol SecondDelagate { func sendValue(text : String!) -> Void } 2.声明代理属性 var delegate : ...
- JVM运行和类加载过程
JAVA的JVM的内存可分为3个区:堆(heap).栈(stack)和方法区(method) (该知识点引用 http://www.cnblogs.com/dingyingsi/p/3760730.h ...
- win7下Apache2.4安装、配置及服务自启动
为了测试微信平台接口,在电脑上安装的Apache服务器,把安装步骤记下来以后备用 第一篇文章,不好请见谅 Apache2.4.17下载地址:http://www.apachelounge.com/do ...