UIImagePickerController是用于选取现有照片,或者用照相机现场照一张相片使用的

定义:

@interface ShowViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

UIImagePickerController * imagePicker;

这里需要注意,Delegate可以不写,但是不写会有警告发生,所以还是写上比较好

使用:

    imagePicker = [[UIImagePickerControlleralloc]init];

    UIImagePickerControllerSourceTypesoureType;

    //soureType当改成UIImagePickerControllerSourceTypeCamera时为照相机照照片模式,UIImagePickerControllerSourceTypePhotoLibrary为相册选取模式

    soureType = UIImagePickerControllerSourceTypePhotoLibrary;

    imagePicker.delegate =self;

    imagePicker.allowsEditing = YES;

    imagePicker.sourceType = soureType;

    

    UIDevice *device  = [UIDevice currentDevice];

    NSLog(@"device.model %@",device.model);

    

    [selfpresentViewController:imagePickeranimated:YEScompletion:^(void){

        

    }];

现在我使用的总共是两种模式,两种模式的切换全都在SoureType里面

最后一句presentViewController用的是切换视图,把当前视图切换到选取照片的视图或者拍照片的视图。

必须实现的接口方法:

 

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

{

    

    inputImage = [info objectForKey:UIImagePickerControllerEditedImage];

    [picker dismissViewControllerAnimated:YEScompletion:^(void){

        

    }];

    [appDelegatesetInputImage:inputImage];

}

 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    [picker dismissViewControllerAnimated:YEScompletion:^(void){

        

    }];

}

第一个方法是在选取照片以后,对照片的存储。通过info找到照片,并放到需要的地方。然后一句话是退出当前视图dismissViewController

第二个方法是取消照片选取以后的方法,这里我不需要进行任何动作,只需要退出当前视图就够了

 

最新文章

  1. datatables中的Options总结(2)
  2. .htaccess 的写法
  3. Unity 坐标系
  4. IOS NSThread
  5. 小而美的js程序
  6. Xcode中的几个常用文件路径
  7. 【Siverlight - 扩展篇】Silverlight在OOB模式下实现默认打开最大化
  8. 30.SSH配置文件模板.md
  9. MEAN全栈开发实践
  10. ios控件 UIImageView
  11. IIS易混概念小结
  12. maven入门(7)maven项目(组件)的坐标
  13. 第五节: EF高级属性(一) 之 本地缓存、立即加载、延迟加载(不含导航属性)
  14. 使用node去爬虫
  15. Android中使用Log4j及配置说明
  16. 31. The New Bread Earners 挣钱养家的新军
  17. cross-compler toolchains--clfs
  18. 从HiveQL到MapReduce job过程简析
  19. dubbo获取错误ip
  20. 给tomcat7w.exe改名字

热门文章

  1. c语言学习之基础知识点介绍(七):循环结构
  2. Linq- ExcuteQuery用法
  3. HTML5教程:课时一HTML简介
  4. (转)iOS被开发者遗忘在角落的NSException-其实它很强大
  5. 分享一个在PearOS里面的plank的配置文件
  6. hdoj(3790) 最短路径
  7. Introduction to object
  8. 如何让你的eclipse运行更快和eclipse常用快捷键
  9. phpcms安装完成后总是跳转到install/install.php
  10. sql server 数据库基础学习心得 思维导图