IOS 在Ipad 横屏 上使用UIImagePickerController
转载前请注明来源:http://www.cnblogs.com/niit-soft-518/p/4381328.html
最近在写一个ipad的项目,该项目必须是横屏。进入正题,有一项功能是要调用系统的牌照和相册,于是本屌用了 UIImagePickerController,兴冲冲的运行了一下,呵呵,崩掉了,然后带着高逼格去查苹果文档,一堆英文,不懂,好吧,百度一下,发现好多同道中人说 UIImagePickerController必须要竖屏,不能横屏~这让我差点泪崩,又继续看苹果文档,发现了新大陆:
Present the user interface. On iPhone or iPod touch, do this modally (full-screen) by calling the
presentViewController:animated:completion:method of the currently active view controller, passing your configured image picker controller as the new view controller.On iPad, the correct way to present an image picker depends on its source type, as summarized in this table:
Camera
Photo Library
Saved Photos Album
Use full screen
Must use a popover
Must use a popover
The table indicates that on iPad, if you specify a source type of
UIImagePickerControllerSourceTypePhotoLibraryorUIImagePickerControllerSourceTypeSavedPhotosAlbum, you must present the image picker using a popover controller, as described in Presenting and Dismissing the Popover. If you attempt to present an image picker modally (full-screen) for choosing among saved pictures and movies, the system raises an exception.On iPad, if you specify a source type of
UIImagePickerControllerSourceTypeCamera, you can present the image picker modally (full-screen) or by using a popover. However, Apple recommends that you present the camera interface only full-screen.
好吧,以我四级未过的英语水平就不做翻译了,大概的意思就是说 如果在ipad中用uiimagepickercontroller,如果调用本地相册,必须使用POPOverController,如果要调用本地相机,可是将modalPresentationStyle属性设置为UIModalPresentationFullScreen也可以设置为popover,苹果推荐设置为全屏的fullscreen。设置然后我就试着写了一下,果然很OK!
以下是代码:
一个调用相册的功能:
/*
相册
*/
-(void)Photo:(UIButton *)sender{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 编辑模式
imagePicker.allowsEditing=NO;
UIPopoverController *pop=[[UIPopoverController alloc]initWithContentViewController:imagePicker];
// [self presentViewController:imagePicker animated:YES completion:NULL];
[pop presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
效果:

iOS8以下推荐使用
UIAlertAction *action_one = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
NSLog(@"打开相册");
[imgPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
imgPicker.modalPresentationStyle = UIModalPresentationPopover; //调用本地相册,必须使用popover
popPC =imgPicker.popoverPresentationController;
[popPC setBarButtonItem:[[UIBarButtonItem alloc]initWithCustomView:bt]];
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popPC.delegate=self;
[self presentViewController:imgPicker animated:false completion:nil];
}else{
[SVProgressHUD showErrorWithStatus:@"请前往设置界面允许程序访问相册!"];
}
}];
[sheet addAction:action_one];
UIAlertAction *action_two = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSLog(@"打开相机");
[imgPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
imgPicker.modalPresentationStyle = UIModalPresentationFullScreen; //苹果推荐使用全屏
popPC =imgPicker.popoverPresentationController;
[popPC setBarButtonItem:[[UIBarButtonItem alloc]initWithCustomView:bt]];
[popPC setSourceRect:CGRectMake(, , , )];
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popPC.delegate=self;
[self presentViewController:imgPicker animated:false completion:nil];
}else{
[SVProgressHUD showErrorWithStatus:@"请前往设置界面允许程序访问摄像头!"];
}
}];
IOS 在Ipad 横屏 上使用UIImagePickerController的更多相关文章
- iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法(任意页面横竖屏或禁止)
iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法 时间 2015-07-14 20:59:00 博客园-原创精华区 原文 http://www.cnblogs.com/fe ...
- iOS 自定义控件开发(上)
工作需要,最近在进行iOS方面的图表工作.找了很多第三方库都无法实现效果,所以决定自己写一个控件. <iOS 自定义控件开发(上)> <iOS 自定义控件开发(中)> #0 目 ...
- iOS部分页面横屏显示
在iOS系统支持横屏顺序默认读取plist里面设置的方向(优先级最高)等同于Xcode Geneal设置里面勾选application window设置的级别次之 然后是UINavigationcon ...
- 李洪强iOS经典面试题上
李洪强iOS经典面试题上 1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ / ...
- 毫无保留开源我写的:IOS Android Ipad 多点触摸通用js 库
毫无保留开源我写的:IOS Android Ipad 多点触摸通用js 库 在线演示地址: http://m.yunxunmi.com/ 支持 IOS Android Ipad 等不同操作系统的手持或 ...
- 在iOS App的图标上显示版本信息
最近读到一篇文章(http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/)介绍了一种非 ...
- IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例
IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...
- 不推荐在iOS的浏览器应用上使用click和mouseover
iOS上的Safari也支持click 和mouseover等传统的交互事件,只是不推荐在iOS的浏览器应用上使用click和mouseover,因为这两个事件是为了支持鼠标点击而设计 出来的.Cli ...
- IOS 横屏中添加UIImagePickerController获取系统图片
今天写ipad的项目,然后需要调用系统相册选择图片,然后用了UIImagePickerController ,崩溃了,后来查了一下,UIImagePickerController只支持竖屏,但是... ...
随机推荐
- javeWeb常用快捷键 Junit for changeableargs enumn reflect
*1 工具常用的快捷键 1) Eclipse和MyEclipse,IBM,2001,Java编写,开源,跨平台跨语言 2)Alt+/快速内容提示 3)Ctrl+1快速修补错误 4)Syso ...
- nginx+lua+redis实现logserver
http://www.baidu.com/s?wd=nginx lua&pn=10&oq=nginx lua&tn=baiduhome_pg&ie=utf-8& ...
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- poj 3253 Fence Repair (哈夫曼树 优先队列)
题目:http://poj.org/problem?id=3253 没用long long wrong 了一次 #include <iostream> #include<cstdio ...
- jquery serialize()方法的扩展
Jquery提供的序列化表单方法serialize方法确实方便,但是我在使用的时候发现了一个弊端:当我使用type:“post”进行ajax请求的时候, 这个时候参数data:$("#myf ...
- SCOI2009游戏
1025: [SCOI2009]游戏 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1065 Solved: 673[Submit][Status] ...
- c语言编译预处理和条件编译执行过程的理解
在C语言的程序中可包括各种以符号#开头的编译指令,这些指令称为预处理命令.预处理命令属于C语言编译器,而不是C语言的组成部分.通过预处理命令可扩展C语言程序设计的环境. 一.预处理的工作方式 1.1. ...
- 使用SignalR 提高B2C商城用户体验1
vs2010 使用SignalR 提高B2C商城用户体验(一) 1.需求简介,做为新时代的b2c商城,没有即时通讯,怎么提供用户粘稠度,怎么增加销量,用户购物的第一习惯就是咨询,即时通讯,应运而生.这 ...
- 【JMeter】Jmeter-完成一个http压力测试
一 新建一个jmeter项目 1 进入/jmeter/bin路径,双击jmeter.bat,在win环境下启动jmeter. 2 点击"编辑->添加->TreadUsers-&g ...
- 【转】Qt Creator在Windows上的调试器安装与配置
https://www.librehat.com/qt-creator-on-windows-debugger-installation-and-configuration/