记得添加MobileCoreServices.framework

及导入#import <MobileCoreServices/MobileCoreServices.h>

  1. @interface PPViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
  2.  
  3. {
  4.  
  5. UIImagePickerController *_pickerController;
  6.  
  7. }
  8.  
  9. @property (weak, nonatomic) IBOutlet UIImageView *imageView;
  10.  
  11. @end
  12.  
  13. @implementation PPViewController
  14.  
  15. - (void)viewDidLoad
  16.  
  17. {
  18.  
  19. [super viewDidLoad];
  20.  
  21. _pickerController = [[UIImagePickerController alloc] init];
  22.  
  23. _pickerController.delegate = self;//设置代理
  24.  
  25. _pickerController.allowsEditing = YES;//图片可编辑(放大缩小)
  26.  
  27. }
  28.  
  29. - (IBAction)choseImage:(id)sender
  30.  
  31. {
  32.  
  33. // 判断是否有相机
  34.  
  35. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
  36.  
  37. {
  38.  
  39. //判断是否能摄像
  40.  
  41. if ([[UIImagePickerController availableMediaTypesForSourceType:_pickerController.sourceType] containsObject:(NSString *)kUTTypeMovie])
  42.  
  43. {
  44.  
  45. _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
  46.  
  47. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"相册",@"相机",@"摄像机", nil];
  48.  
  49. sheet.tag = ;
  50.  
  51. [sheet showInView:self.view];
  52.  
  53. }
  54.  
  55. else
  56.  
  57. {
  58.  
  59. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"相机",@"相册", nil];
  60.  
  61. sheet.tag = ;
  62.  
  63. [sheet showInView:self.view];
  64.  
  65. }
  66.  
  67. }
  68.  
  69. else
  70.  
  71. {//模拟器
  72.  
  73. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"相册", nil];
  74.  
  75. sheet.tag = ;
  76.  
  77. [sheet showInView:self.view];
  78.  
  79. }
  80.  
  81. }
  82.  
  83. #pragma mark- UIActionSheet的代理方法
  84.  
  85. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  86.  
  87. {
  88.  
  89. if (actionSheet.tag == )
  90.  
  91. {
  92.  
  93. switch (buttonIndex)
  94.  
  95. {
  96.  
  97. case :
  98.  
  99. {
  100.  
  101. _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  102.  
  103. _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
  104.  
  105. [self presentViewController:_pickerController animated:YES completion:nil];
  106.  
  107. }
  108.  
  109. break;
  110.  
  111. case :
  112.  
  113. {
  114.  
  115. _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  116.  
  117. _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
  118.  
  119. [self presentViewController:_pickerController animated:YES completion:nil];
  120.  
  121. }
  122.  
  123. break;
  124.  
  125. default:
  126.  
  127. break;
  128.  
  129. }
  130.  
  131. }
  132.  
  133. if (actionSheet.tag == )
  134.  
  135. {
  136.  
  137. switch (buttonIndex)
  138.  
  139. {
  140.  
  141. case :
  142.  
  143. {
  144.  
  145. _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  146.  
  147. _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
  148.  
  149. [self presentViewController:_pickerController animated:YES completion:nil];
  150.  
  151. }
  152.  
  153. break;
  154.  
  155. case :
  156.  
  157. {
  158.  
  159. _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  160.  
  161. // _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
  162.  
  163. [self presentViewController:_pickerController animated:YES completion:nil];
  164.  
  165. }
  166.  
  167. break;
  168.  
  169. case :
  170.  
  171. {
  172.  
  173. _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  174.  
  175. // pickController.videoQuality = UIImagePickerControllerQualityTypeLow;//可以选择图片质量
  176.  
  177. _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
  178.  
  179. [self presentViewController:_pickerController animated:YES completion:nil];
  180.  
  181. }
  182.  
  183. default:
  184.  
  185. break;
  186.  
  187. }
  188.  
  189. }
  190.  
  191. if (actionSheet.tag == )
  192.  
  193. {
  194.  
  195. if (buttonIndex == )
  196.  
  197. {
  198.  
  199. _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  200.  
  201. // _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
  202.  
  203. [self presentViewController:_pickerController animated:YES completion:nil];
  204.  
  205. }
  206.  
  207. }
  208.  
  209. }
  210.  
  211. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  212.  
  213. {
  214.  
  215. NSLog(@"========%@",info);//返回的值都在info里面
  216.  
  217. if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie])
  218.  
  219. {
  220.  
  221. _imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:(NSString *)[[info objectForKey:UIImagePickerControllerMediaURL] path]]];
  222.  
  223. }
  224.  
  225. else
  226.  
  227. {
  228.  
  229. _imageView.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
  230.  
  231. }
  232.  
  233. [self dismissViewControllerAnimated:YES completion:nil];
  234.  
  235. }
  236.  
  237. //如果这是一个modalViewController,需要dismiss 它发了个cancel消息,必须关闭它
  238.  
  239. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  240.  
  241. {
  242.  
  243. [self dismissViewControllerAnimated:YES completion:nil];
  244.  
  245. }
  246.  
  247. /**
  248.  
  249. * {
  250.  
  251. UIImagePickerControllerMediaType = "public.image";
  252.  
  253. UIImagePickerControllerOriginalImage = "<UIImage: 0x7fe3a3dc2a20> size {1500, 1001} orientation 0 scale 1.000000";
  254.  
  255. UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=B6C0A21C-07C3-493D-8B44-3BA4C9981C25&ext=JPG";
  256.  
  257. }
  258.  
  259. */
  260.  
  261. /**
  262.  
  263. * {
  264.  
  265. UIImagePickerControllerCropRect = "NSRect: {{0, 0}, {1500, 1003}}";
  266.  
  267. UIImagePickerControllerEditedImage = "<UIImage: 0x7fec5c8145b0> size {638, 426} orientation 0 scale 1.000000";
  268.  
  269. UIImagePickerControllerMediaType = "public.image";
  270.  
  271. UIImagePickerControllerOriginalImage = "<UIImage: 0x7fec5c80d4c0> size {1500, 1001} orientation 0 scale 1.000000";
  272.  
  273. UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=B6C0A21C-07C3-493D-8B44-3BA4C9981C25&ext=JPG";
  274.  
  275. }
  276.  
  277. */

ios中关于UIImagePickerController的一些知识总结的更多相关文章

  1. Android 和iOS 中关于View 的一点知识

    View的概念和方法十分重要,这里将对Android 和iOS中出现的,关于视图的一些知识点进行总结,预计文章会比较长,要许多时间慢慢补充. 先转载一部分资料,感谢原作者! 原链接为:http://b ...

  2. ios中改变UIImagePickerController页面的button的文字为中文

    可以在工程中直接 project-->info-->Localization native development region   赋值为 zh_CN

  3. iOS中多线程知识总结(一)

    这一段开发中一直在处理iOS多线程的问题,但是感觉知识太散了,所以就把iOS中多线程的知识点总结了一下. 1.基本概念 1)什么是进程?进程的特性是什么? 进程是指在系统中正在运行的一个应用程序.   ...

  4. iOS狂暴之路---iOS的第一个应用中能学到哪些知识

    一.前文回顾 在之前已经介绍了 iOS的学习路线图,因为中间遇到一些Android开发问题,所以就耽搁了一段时间,那么接下来的这段时间我们将继续开始iOS的狂暴之路学习,按照国际惯例,第一个应用当然是 ...

  5. ios 中使用https的知识

    先看文章,这篇文章说的是使用AFNetworing进行https时的事项,十分好!http://blog.cnbang.net/tech/2416/ ios中使用https,主要就是使用NSURLCr ...

  6. ios中摄像头/相册获取图片压缩图片上传服务器方法总结

    本文章介绍了关于ios中摄像头/相册获取图片,压缩图片,上传服务器方法总结,有需要了解的同学可以参考一下下.     这几天在搞iphone上面一个应用的开发,里面有需要摄像头/相册编程和图片上传的问 ...

  7. Cordoval在iOS中的运用整理

    一:关于Cordoval理论知识 1:PhoneGap是手机平台上流行的一款中间件.它构建在各种手机平台所提供的WebView(浏览器内核)组件的基础之上,使用javascript语言对应用开发者提供 ...

  8. ios中的几种多线程实现

    iOS 支持多个层次的多线程编程,层次越高的抽象程度越高,使用起来也越方便,也是苹果最推荐使用的方法.下面根据抽象层次从低到高依次列出iOS所支持的多线程编程范式:1, Thread;2, Cocoa ...

  9. IOS中调用系统的电话、短信、邮件、浏览功能

    iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...

随机推荐

  1. vb.net_介绍

    手打 vb.net 是 visual basic.net的简称.提到vb.net,就不能不先提一下vb(Visual Basic) Visaul Basic是windows环境学的一个简单.易学的编程 ...

  2. 认识<meta>

    概要:在查看网页源码的时候,经常发现有<meta>标签存在,于是查了一下它的作用,发现有很多功能.下面就简单的阐述一些常见的功能. 一[什么是<meta>标签] meta,即m ...

  3. article标签和aside标签两者的理解

    article标签,使用后感觉和P(段落)差不多,语义化的标签.<aside> 标签定义article以外的内容(可用做文章的侧栏). 语义化的标签.  html 标签有几种分类,其中有一 ...

  4. Amazon EC2 的名词解释

    Amazon EC2   Amazon Elastic Compute Cloud (Amazon EC2) Amazon EC2 提供以下功能: 实例:虚拟计算环境 实例预配置模板/Amazon 系 ...

  5. [SQL基础教程]1-4 SQL 表的创建

    [SQL基础教程]1-4 SQL 表的创建 创建数据库 语法 CREATE DATABASE <数据库名称> // example CREATE DATABASE shop; 创建表 语法 ...

  6. React 相关资料

    learncodeacademy/react-js-tutorials MobX

  7. Hoffmann树

    数据压缩编码 先把两棵二叉树简化成叶子结点带权的二叉树,图的每个结点之间带有权值 结点的路径长度: 从根结点到该结点的路径上的连接数. 树的路径长度: 树中每个叶子结点的路径长度之和. 结点带权路径长 ...

  8. ftp资源调用迅雷下载

    <script src='http://pstatic.xunlei.com/js/webThunderDetect.js'></script> <script src= ...

  9. incallui中如何查询联系人数据

    联系人信息显示在CallCard中,提示当前正在通话的联系人号码.姓名.头像.号码类型等信息: 代码中在两个地方发起对当前联系人的查询, Init():startContactInfoSearch(c ...

  10. protected-broadcast的作用

    protected-broadcast(暂时从网上搜到这么多,也不知对错,先留着) “保护性广播”,在一些AndroidManifest.xml中的一级标记<protected-broadcas ...