转载自:http://blog.csdn.net/like7xiaoben/article/details/8465237

  1. //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库
  2. UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
  3. //    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
  4. //        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  5. //    }
  6. //sourceType = UIImagePickerControllerSourceTypeCamera; //照相机
  7. //sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库
  8. //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片
  9. UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
  10. picker.delegate = self;
  11. picker.allowsEditing = YES;//设置可编辑
  12. picker.sourceType = sourceType;
  13. [self presentModalViewController:picker animated:YES];//进入照相界面
  14. [picker release];

打开相册:(区分pad和iphone)

for iphone:

  1. UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
  2. if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
  3. pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  4. //pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
  5. pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
  6. }
  7. pickerImage.delegate = self;
  8. pickerImage.allowsEditing = NO;
  9. [self presentModalViewController:pickerImage animated:YES];
  10. [pickerImage release];

for ipad:

  1. UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  2. //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片
  3. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  4. picker.delegate = self;
  5. picker.allowsEditing = NO;//是否允许编辑
  6. picker.sourceType = sourceType;
  7. /*
  8. 如果从一个导航按钮处呈现,使用:
  9. presentPopoverFromBarButtonItem:permittedArrowDirections:animated:;
  10. 如果要从一个视图出呈现,使用:
  11. presentPopoverFromRect:inView:permittedArrowDirections:animated:
  12. 如果设备旋转以后,位置定位错误需要在父视图控制器的下面方法里面重新定位:
  13. didRotateFromInterfaceOrientation:(在这个方法体里面重新设置rect)
  14. 然后再次调用:
  15. - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
  16. */
  17. //UIPopoverController只能在ipad设备上面使用;作用是用于显示临时内容,特点是总是显示在当前视图最前端,当单击界面的其他地方时自动消失。
  18. UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:picker];
  19. self.imagePicker = popover;
  20. //permittedArrowDirections 设置箭头方向
  21. [self.imagePicker presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  22. [picker release];
  23. [popover release];

点击相册中的图片 货照相机照完后点击use  后触发的方法

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

点击cancel 调用的方法

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

例子下载地址:http://download.csdn.net/download/like7xiaoben/4958356

IOS成长之路-调用照相机和相册功能(转)的更多相关文章

  1. IOS成长之路-调用照相机和相册功能

    打开相机: //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库 UIImagePickerControllerSourceType ...

  2. 转:HTML5页面如何在手机端浏览器调用相机、相册功能

    HTML5页面如何在手机端浏览器调用相机.相册功能 开发微信端浏览器访问的HTML5的页面,页面中有一个<input id="input" type="file&q ...

  3. HTML5页面如何在手机端浏览器调用相机、相册功能

    最近在做一个公司的保险信息处理系统项目,开发微信端浏览器访问的HTML5的页面,页面中有一个<input id="input" type="file"/& ...

  4. iOS UIWebView 中 js调用OC 打开相册 获取图片, OC调用js 将图片加载到html上

    线上html <!DOCTYPE html> <html> <head> <title>HTML中用JS调用OC方法</title> < ...

  5. IOS成长之路-Xcode cannot run using the selected device. 解决办法

    PROJECT --> Info --> Deployment Target --> IOS Deployment Target  里面的值 要设置为  <=真机系统版本 TA ...

  6. IOS成长之路-Nsstring中搜索方法rangeOfString

    NSString *str1 = @"can you \n speak English"; NSString *str = @"\n"; //在str1这个字符 ...

  7. IOS成长之路-Nsstring搜索方法rangeOfString

    NSString *str1 = @"can you \n speak English"; NSString *str = @"\n"; //在str1该字符串 ...

  8. IOS成长之路-用NSXMLParser实现XML解析

    再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...

  9. iOS成长之路-使用系统默认声音、震动

    导入框架 代码片段 apple系统默认声音名称说明: 1.声音格式是MP3或m4r的需要转成caf格式(可先转成aif , aiff,然后修改后缀) 2.路径在/System/Library/Audi ...

随机推荐

  1. hdu 1059 多重背包 背包指数分块

    思路: 这个方法要看<浅谈几类背包问题>这篇论文. #include"stdio.h" #define Max(a,b) (a)>(b)?(a):(b) ],k[ ...

  2. Leetcode 338. Counting Bits

    Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...

  3. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  4. [算法练习] UVA 10420 - List of Conquests?

    UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加, ...

  5. 原生js 实现的瀑布流

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. JS中的嵌套作用域

    在JS中仅仅区分全局变量和局部变量还不够,实际上,变量作用域可以有任意层级(嵌套).其他函数内部定义的函数可以调用父函数的局部变量,而内部函数里定义的函数则不仅可以调用父函数的局部变量,还可以调用祖父 ...

  7. JMS - 事务性消息

    JMS 事务遵从发送操作与接收操作相互分离的约定.下图显示的是一个事务性发送,其中一组消息要么能够保证全部到达消息服务器,要么连一条消息也不能保证到达消息服务器.从发送者的角度来看,JMS 提供者为这 ...

  8. Linux 命令 - chown: 更改文件的所有者和所属群组

    chown 命令用来更改文件或者目录的所有者和所属群组.使用这个命令需要超级用户的权限. 命令格式 chown [OPTION]... [OWNER][:[GROUP]] FILE... chown ...

  9. 整合Spring与Hibernate

    在学习spring的时候,要整合hibernate,本来是看起来挺简单的,但是遇到的远要比想到了多,而且多很多,期间几天一个bug实在难调,几度放弃,但终究柳暗花明,抑制不住喜悦就想着分享一下成果吧. ...

  10. Android之屏幕测试

    MainActivity: package com.example.touchscreentest; import android.os.Bundle; import android.R.layout ...