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
UIImagePickerControllerSourceTypePhotoLibrary
orUIImagePickerControllerSourceTypeSavedPhotosAlbum
, 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只支持竖屏,但是... ...
随机推荐
- (转)CAP理论十二年回顾:"规则"变了
编者按:由InfoQ主办的全球架构师峰会将于2012年8月10日-12日在深圳举行,为了更好地诠释架构的意义.方法和实践,InfoQ中文站近期会集中发布一批与架构相关的文章,本篇即为其中之一.Info ...
- pb 插入控件是出问题
http://m.blog.csdn.net/blog/jqz1225/34417493 是的http://blog.163.com/wufeng_1213/blog/static/167783313 ...
- python web开发遇到socket.error[errno 10013]
socket.error[errno 10013],端口被占用 重新换一个端口,或者把占用该端口的程序关闭就可以了
- 函数buf_LRU_get_free_block
/******************************************************************//** Returns a free block from th ...
- 结构体 typedef struct hash_cell_struct hash_cell_t;
typedef struct hash_cell_struct hash_cell_t; struct hash_cell_struct{ void* node; /*!< hash chain ...
- poj1947
树上背包? 问最少断掉多少条边可以形成节点数为k的块 设f[i,j]表示以节点i为根,形成一个节点数为k的块要断多少条边 则有:f[x,j]:=min(f[x,j],f[x,j-k]+f[y,k]-2 ...
- eayui 验证扩展
$.extend($.fn.validatebox.defaults.rules, { idcard : {// 验证身份证 validator : function(value) { return ...
- 剑指Offer:互为变位词
// 判断两个单词是否互为变位词: 如果两个单词中的字母相同,并且每个字母出现的次数也相同, 那么这两个单词互为变位词 #include <stdio.h> #include <st ...
- MYSQL select时锁定记录问题
在使用SQL时,大都会遇到这样的问题,你Update一条记录时,需要通过Select来检索出其值或条件,然后在通过这个值来执行修改操作. 但当以上操作放到多线程中并发处理时会出现问题:某线程selec ...
- Kettle定时执行(ETL工具)【转】
1,Kettle跨平台使用. 例如:在AIX下(AIX是IBM商用UNIX操作系统,此处在LINUX/UNIX同样适用),运行Kettle的相关步骤如下: 1)进入到Kettle部署的路径 ...