IOS成长之路-调用照相机和相册功能
打开相机:
//先设定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];
在iPhone和iPod touch上面系统始终以UIModalPresentationFullScreen模式显示presented VC。
打开相册:(区分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:
On iPad, UIImagePickerController must be presented via UIPopoverController
不是你想不想的问题,是苹果让你想不想的问题
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(, , , ) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[picker release];
[popover release];
IOS成长之路-调用照相机和相册功能的更多相关文章
- IOS成长之路-调用照相机和相册功能(转)
转载自:http://blog.csdn.net/like7xiaoben/article/details/8465237 //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机 ...
- 转: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 ...
随机推荐
- poj 2976 Dropping tests 0/1分数规划
0/1分数规划问题,用二分解决!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> # ...
- Web Api 入门
http://www.cnblogs.com/developersupport/p/WebAPI-Security.html http://www.cnblogs.com/r01cn/archive/ ...
- Some projects cannot be imported because they already exist in the workspace
原文地址: Some projects cannot be imported because they already exist in the workspace - 浅尝辄止的博客 - 博客频道 ...
- Linux下安装Wine运行windows程序
资料 首页 https://www.winehq.org/ 安装 https://www.winehq.org/download/ 教程 https://www.winehq.org/document ...
- python操作Excel读--使用xlrd
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 import x ...
- poj 2533 Longest Ordered Subsequence(dp)
题目:http://poj.org/problem?id=2533 题意:最长上升子序列.... 以前做过,课本上的思想 #include<iostream> #include<cs ...
- poi对wps excel的支持
今天在使用poi解析xls文件的时候出现了如下异常 Exception in thread"main"java.lang.RuntimeException: Expected an ...
- Webform——Repeater多表联合显示
对于一个表里,通过外键连接如何显示另一个表的数据,前Winform里可以用封装类来实现. 对于Webform,可以用封装类,也可以用Repeater的ItemDataBound事件(//在项被绑定数据 ...
- 一种基于Storm的可扩展即时数据处理架构思考
问题引入 使用storm可以方便的构建一种集群式的数据框架,并通过定义topo来实现业务逻辑. 但使用topo存在一个缺点, topo的处理能力来自于其启动时设置的worker数目,在很多情况下,我们 ...
- bzoj3774
这算是最小割中比较难的吧 看到选取显然最小割 看到上下左右四个点我感觉肯定和染色相关 注意每个点的收益获得条件是[或],因此我们考虑拆点i', i,分别表示通过四周控制和控制本身的代价 连边s--&g ...