ios中关于UIImagePickerController的一些知识总结

记得添加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 = 2;

[sheet showInView:self.view];

}

else

{

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

sheet.tag = 1;

[sheet showInView:self.view];

}

}

else

{//模拟器

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

sheet.tag = 3;

[sheet showInView:self.view];

}

}

#pragma mark- UIActionSheet的代理方法

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

{

if (actionSheet.tag == 1)

{

switch (buttonIndex)

{

case 0:

{

_pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

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

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

}

break;

case 1:

{

_pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

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

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

}

break;

default:

break;

}

}

if (actionSheet.tag == 2)

{

switch (buttonIndex)

{

case 0:

{

_pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

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

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

}

break;

case 1:

{

_pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

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

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

}

break;

case 2:

{

_pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

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

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

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

}

default:

break;

}

}

if (actionSheet.tag == 3)

{

if (buttonIndex == 0)

{

_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";

}

*/

时间: 2024-08-08 15:49:07

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

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

今天调用系统的照相和本地相册,编辑图片的功能,但是按钮都是英文,我想改为中文的  取消,选择,重拍 需要改变两种方法 1. UIImagePickerController页面的Cancel和Choose按钮以及截取中得重拍按钮,想改成中文 本来打算通过获取这些按钮的指针进行设置的,最后发现可以在工程中直接 project-->info-->Localization--->language中add一个简体中文就可以了 参考:http://www.cocoachina.com/bbs/rea

IOS中UIImagePickerController中文界面问题

今天沈阳斌子,写IOS项目遇到一个调用照相机的问题,找到解决方法,快速解决了拿给PM看,结果PM说程序调用的照相机不是中文的是英文的,必须改成中文,上网找到了方法,试用后好用拿出来和大家分享.方法如下,总共分两步: 一: Target-->Localization native development region : China 本地化的开发语言版本选择China 没有的话添加一下. 二:Project-->Localizations  添加Chinese 中文包 这点挺重要的要想实现中文显

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

这一段开发中一直在处理iOS多线程的问题,但是感觉知识太散了,所以就把iOS中多线程的知识点总结了一下. 1.基本概念 1)什么是进程?进程的特性是什么? 进程是指在系统中正在运行的一个应用程序.    特性: 每个进程之间都是独立的,每个进程都运行在其专用而且受保护的内存空间内. 2)什么是线程?线程和进程的关系是什么? 一个进程要想执行任务,必须要有线程(每一个进程至少要有一个线程),线程是进程的基本单元,一个进程中的所有任务都是在线程中执行 关系: 进程包含线程 3)什么叫多线程? 一个进

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

一.前文回顾 在之前已经介绍了 iOS的学习路线图,因为中间遇到一些Android开发问题,所以就耽搁了一段时间,那么接下来的这段时间我们将继续开始iOS的狂暴之路学习,按照国际惯例,第一个应用当然是我们的HelloWorld程序了.那么本文将会通过这么一个简单的程序来讲解一下iOS中的程序生命周期,应用中关键的几个对象,项目结构,最后在手把手的创建一个空项目. 二.建立简单程序HelloWorld 下面先用Xcode来新建一个HelloWorld程序: 点击下一步即可: 这里和我们在Andro

ios 中使用https的知识

先看文章,这篇文章说的是使用AFNetworing进行https时的事项,十分好!http://blog.cnbang.net/tech/2416/ ios中使用https,主要就是使用NSURLCredential,先看些必要的官方文档: NSURLCredential is an immutable object representing an authentication credential consisting of authentication information specifi

ios中UIControl详解

上篇讲到了UITouch和UIEvent事件,简单回顾一下,UIEvent是一系列UITouch的集合,在IOS中负责响应触摸事件.另外还提到了响应者链的概念,在IOS中,所有事件有一个最先响应者,事件可以沿着响应者链向下传递. 接下来是UIControl对象 UIControl是UIView的子类,当然也是UIResponder的子类.UIControl是诸如UIButton.UISwitch.UITextField等控件的父类,它本身也包含了一些属性和方法,但是不能直接使用UIControl

OS X 和iOS 中的多线程技术(上)

OS X 和iOS 中的多线程技术(上) 本文梳理了OS X 和iOS 系统中提供的多线程技术.并且对这些技术的使用给出了一些实用的建议. 多线程的目的:通过并发执行提高 CPU 的使用效率,进而提供程序运行效率. 1.线程和进程 进程 什么是进程 进程是指在计算机系统中正在运行的一个应用程序 每个进程之间是独立的,每个进程均运行中其专用且受保护的内存空间内 比如同时打开 Xcode .Safari ,系统就会分别启动两个进程 通过活动监视器可以查看Mac系统中所开启的进程 线程 什么是线程 一

iOS中Animation 动画 UI_22

1.iOS中我们能看到的控件都是UIView的子类,比如UIButton UILabel UITextField UIImageView等等 2.UIView能够在屏幕的显示是因为在创建它的时候内部自动添加一个CALayer图层,通过这个图层在屏幕上显示的时候会调用一个drawRect: 的方法,完成绘图,才能在屏幕上显示 3.CALayer 本身就具有显示功能,但是它不能响应用户的交互事件,如果只是单纯的显示一个图形,此时你可以使用CALayer创建或者是使用UIView创建,但是如果这个图形

如何在iOS中使用Block

如何在iOS中使用Block Block可以帮助我们组织独立的代码段,并提高复用性和可读性.iOS4在UIKit中引入了该特征.超过100个的Apple API都使用了Block,所以这是一个我们必须开始熟悉的知识. Block是什么样的? 你可以使用^操作符来声明一个Block变量,它表示一个Block的开始. int num1 = 7; int(^aBlock)(int) = ^)int num2) { return num1+nunm2; }; 在如上代码中我们将Block声明为一个变量,