IOS成长之路-调用照相机和相册功能(转)
转载自:http://blog.csdn.net/like7xiaoben/article/details/8465237
- //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库
- UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
- // if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
- // sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- // }
- //sourceType = UIImagePickerControllerSourceTypeCamera; //照相机
- //sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库
- //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
- picker.delegate = self;
- picker.allowsEditing = YES;//设置可编辑
- picker.sourceType = sourceType;
- [self presentModalViewController:picker animated:YES];//进入照相界面
- [picker release];
打开相册:(区分pad和iphone)
for iphone:
- UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
- if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
- pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- //pickerImage.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
- pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
- }
- pickerImage.delegate = self;
- pickerImage.allowsEditing = NO;
- [self presentModalViewController:pickerImage animated:YES];
- [pickerImage release];
for ipad:
- UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- //sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片
- UIImagePickerController *picker = [[UIImagePickerController alloc] init];
- picker.delegate = self;
- picker.allowsEditing = NO;//是否允许编辑
- picker.sourceType = sourceType;
- /*
- 如果从一个导航按钮处呈现,使用:
- presentPopoverFromBarButtonItem:permittedArrowDirections:animated:;
- 如果要从一个视图出呈现,使用:
- presentPopoverFromRect:inView:permittedArrowDirections:animated:
- 如果设备旋转以后,位置定位错误需要在父视图控制器的下面方法里面重新定位:
- didRotateFromInterfaceOrientation:(在这个方法体里面重新设置rect)
- 然后再次调用:
- - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated
- */
- //UIPopoverController只能在ipad设备上面使用;作用是用于显示临时内容,特点是总是显示在当前视图最前端,当单击界面的其他地方时自动消失。
- UIPopoverController *popover = [[UIPopoverController alloc]initWithContentViewController:picker];
- self.imagePicker = popover;
- //permittedArrowDirections 设置箭头方向
- [self.imagePicker presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- [picker release];
- [popover release];
点击相册中的图片 货照相机照完后点击use 后触发的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
点击cancel 调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
例子下载地址:http://download.csdn.net/download/like7xiaoben/4958356
IOS成长之路-调用照相机和相册功能(转)的更多相关文章
- IOS成长之路-调用照相机和相册功能
打开相机: //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库 UIImagePickerControllerSourceType ...
- 转:HTML5页面如何在手机端浏览器调用相机、相册功能
HTML5页面如何在手机端浏览器调用相机.相册功能 开发微信端浏览器访问的HTML5的页面,页面中有一个<input id="input" type="file&q ...
- HTML5页面如何在手机端浏览器调用相机、相册功能
最近在做一个公司的保险信息处理系统项目,开发微信端浏览器访问的HTML5的页面,页面中有一个<input id="input" type="file"/& ...
- iOS UIWebView 中 js调用OC 打开相册 获取图片, OC调用js 将图片加载到html上
线上html <!DOCTYPE html> <html> <head> <title>HTML中用JS调用OC方法</title> < ...
- IOS成长之路-Xcode cannot run using the selected device. 解决办法
PROJECT --> Info --> Deployment Target --> IOS Deployment Target 里面的值 要设置为 <=真机系统版本 TA ...
- IOS成长之路-Nsstring中搜索方法rangeOfString
NSString *str1 = @"can you \n speak English"; NSString *str = @"\n"; //在str1这个字符 ...
- IOS成长之路-Nsstring搜索方法rangeOfString
NSString *str1 = @"can you \n speak English"; NSString *str = @"\n"; //在str1该字符串 ...
- IOS成长之路-用NSXMLParser实现XML解析
再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...
- iOS成长之路-使用系统默认声音、震动
导入框架 代码片段 apple系统默认声音名称说明: 1.声音格式是MP3或m4r的需要转成caf格式(可先转成aif , aiff,然后修改后缀) 2.路径在/System/Library/Audi ...
随机推荐
- hdu 1059 多重背包 背包指数分块
思路: 这个方法要看<浅谈几类背包问题>这篇论文. #include"stdio.h" #define Max(a,b) (a)>(b)?(a):(b) ],k[ ...
- Leetcode 338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...
- Leetcode 9. Palindrome Number(判断回文数字)
Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...
- [算法练习] UVA 10420 - List of Conquests?
UVA Online Judge 题目10420 - List of Conquests 问题描述: 题目很简单,给出一个出席宴会的人员列表,包括国籍和姓名(姓名完全没用).统计每个国家有多少人参加, ...
- 原生js 实现的瀑布流
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- JS中的嵌套作用域
在JS中仅仅区分全局变量和局部变量还不够,实际上,变量作用域可以有任意层级(嵌套).其他函数内部定义的函数可以调用父函数的局部变量,而内部函数里定义的函数则不仅可以调用父函数的局部变量,还可以调用祖父 ...
- JMS - 事务性消息
JMS 事务遵从发送操作与接收操作相互分离的约定.下图显示的是一个事务性发送,其中一组消息要么能够保证全部到达消息服务器,要么连一条消息也不能保证到达消息服务器.从发送者的角度来看,JMS 提供者为这 ...
- Linux 命令 - chown: 更改文件的所有者和所属群组
chown 命令用来更改文件或者目录的所有者和所属群组.使用这个命令需要超级用户的权限. 命令格式 chown [OPTION]... [OWNER][:[GROUP]] FILE... chown ...
- 整合Spring与Hibernate
在学习spring的时候,要整合hibernate,本来是看起来挺简单的,但是遇到的远要比想到了多,而且多很多,期间几天一个bug实在难调,几度放弃,但终究柳暗花明,抑制不住喜悦就想着分享一下成果吧. ...
- Android之屏幕测试
MainActivity: package com.example.touchscreentest; import android.os.Bundle; import android.R.layout ...