记得添加MobileCoreServices.framework

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

 @interface PPViewController ()<UIActionSheetDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>

 {

     UIImagePickerController *_pickerController;

 }

 @property (weak, nonatomic) IBOutlet UIImageView *imageView;

 @end

 @implementation PPViewController

 - (void)viewDidLoad

 {

     [super viewDidLoad];

     _pickerController = [[UIImagePickerController alloc] init];

     _pickerController.delegate = self;//设置代理

     _pickerController.allowsEditing = YES;//图片可编辑(放大缩小)

 }

 - (IBAction)choseImage:(id)sender

 {

     // 判断是否有相机

     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

     {

         //判断是否能摄像

         if ([[UIImagePickerController availableMediaTypesForSourceType:_pickerController.sourceType] containsObject:(NSString *)kUTTypeMovie])

         {

             _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];

             UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"相册",@"相机",@"摄像机", nil];

             sheet.tag = ;

             [sheet showInView:self.view];

         }

         else

         {

             UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"相机",@"相册", nil];

             sheet.tag = ;

             [sheet showInView:self.view];

         }

     }

     else

     {//模拟器

         UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"相册", nil];

         sheet.tag = ;

         [sheet showInView:self.view];

     }

 }

 #pragma mark- UIActionSheet的代理方法

 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

 {

     if (actionSheet.tag == )

     {

         switch (buttonIndex)

         {

             case :

             {

                 _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

                 _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];

                 [self presentViewController:_pickerController animated:YES completion:nil];

             }

                 break;

             case :

             {

                 _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

                 _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];

                 [self presentViewController:_pickerController animated:YES completion:nil];

             }

                 break;

             default:

                 break;

         }

     }

     if (actionSheet.tag == )

     {

         switch (buttonIndex)

         {

             case :

             {

                 _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

                 _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];

                 [self presentViewController:_pickerController animated:YES completion:nil];

             }

                 break;

             case :

             {

                 _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

 //                _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];

                 [self presentViewController:_pickerController animated:YES completion:nil];

             }

                 break;

             case :

             {

                 _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

                 //        pickController.videoQuality = UIImagePickerControllerQualityTypeLow;//可以选择图片质量

                 _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];

                 [self presentViewController:_pickerController animated:YES completion:nil];

             }

             default:

                 break;

         }

     }

     if (actionSheet.tag == )

     {

         if (buttonIndex == )

         {

             _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

 //            _pickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];

             [self presentViewController:_pickerController animated:YES completion:nil];

         }

     }

 }

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

 {

     NSLog(@"========%@",info);//返回的值都在info里面

     if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString *)kUTTypeMovie])

     {

         _imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:(NSString *)[[info objectForKey:UIImagePickerControllerMediaURL] path]]];

     }

     else

     {

         _imageView.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

     }

     [self dismissViewControllerAnimated:YES completion:nil];

 }

 //如果这是一个modalViewController,需要dismiss 它发了个cancel消息,必须关闭它

 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

 {

     [self dismissViewControllerAnimated:YES completion:nil];

 }

 /**

  *  {

  UIImagePickerControllerMediaType = "public.image";

  UIImagePickerControllerOriginalImage = "<UIImage: 0x7fe3a3dc2a20> size {1500, 1001} orientation 0 scale 1.000000";

  UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=B6C0A21C-07C3-493D-8B44-3BA4C9981C25&ext=JPG";

  }

  */

 /**

  *  {

  UIImagePickerControllerCropRect = "NSRect: {{0, 0}, {1500, 1003}}";

  UIImagePickerControllerEditedImage = "<UIImage: 0x7fec5c8145b0> size {638, 426} orientation 0 scale 1.000000";

  UIImagePickerControllerMediaType = "public.image";

  UIImagePickerControllerOriginalImage = "<UIImage: 0x7fec5c80d4c0> size {1500, 1001} orientation 0 scale 1.000000";

  UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=B6C0A21C-07C3-493D-8B44-3BA4C9981C25&ext=JPG";

  }

  */

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. 【转】python - PyDev统一编码

    http://www.cnblogs.com/huangjacky/archive/2012/07/15/2592166.html 我们都知道Win7默认编码是GBK,而Ubuntu下面默认是utf- ...

  2. WCF初接触实作

    我们通过实现一个简单的示例来对WCF有个直观而浅显的认识,希望对初次涉及WCF的朋友有所帮助. 可以简单地认为WCF程序分为4部分:契约.服务.宿主.客户端.我们通过一个例子来逐步完成各部分,示例程序 ...

  3. iOS开发The Operation couldn't be completed.(LaunchServicesError error 0.)的解决方法

    显示错误:The Operation couldn't be completed.(LaunchServicesError error 0.)解决办法:第1种方法.点击当前的模拟器,点击IOS Sim ...

  4. Flask-Request对象属性

    Request属性 元属性 method host path environ headers data body中的内容 最安全 解析后 remote_addr args form values  a ...

  5. windows下9款一键快速搭建PHP本地运行环境的好工具(含php7.0环境)

    推荐几款一键快速搭建PHP本地运行环境的好工具(含php7.0及apache,nigix,mysql) 首推phpstudy2016和wampServer3.0.6     理由支持php7.0 目前 ...

  6. 【同行说】Android图片处理技术资料汇总(一)

    对于Android开发的童鞋们来说,图片处理时或多或少都会遇到令人头疼和不满意的问题,今天小编收集了5篇Android图片处理的干货文章,一起来看看吧! 一.Android 高清加载巨图方案 拒绝压缩 ...

  7. Ambari中添加新服务

    官网: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=38571133 一.背景 栈的定义可以在源代码树中找到/am ...

  8. ActiveMQ in Action(4) - Security

    关键字: activemq 2.4 Security    ActiveMQ支持可插拔的安全机制,用以在不同的provider之间切换.2.4.1 Simple Authentication Plug ...

  9. 为什么推荐Zookeeper作注册中心

    Zookeeper的数据模型很简单,有一系列被称为ZNode的数据节点组成,与传统的磁盘文件系统不同的是,zk将全量数据存储在内存中,可谓是高性能,而且支持集群,可谓高可用,另外支持事件监听.这些特点 ...

  10. kali linux 更新软件源,安装中文输入法,修复Linux与windows引导菜单解决windows引导丢失

    1. 更新软件源打开sources.list文件,进行添加更新源:leafpad /etc/apt/sources.list 2. 添加软件源#官方源 deb http://http.kali.org ...