转载前请注明来源:http://www.cnblogs.com/niit-soft-518/p/4381328.html

最近在写一个ipad的项目,该项目必须是横屏。进入正题,有一项功能是要调用系统的牌照和相册,于是本屌用了 UIImagePickerController,兴冲冲的运行了一下,呵呵,崩掉了,然后带着高逼格去查苹果文档,一堆英文,不懂,好吧,百度一下,发现好多同道中人说 UIImagePickerController必须要竖屏,不能横屏~这让我差点泪崩,又继续看苹果文档,发现了新大陆:

  1. 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 or UIImagePickerControllerSourceTypeSavedPhotosAlbum, 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的更多相关文章

  1. iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法(任意页面横竖屏或禁止)

    iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法 时间 2015-07-14 20:59:00  博客园-原创精华区 原文  http://www.cnblogs.com/fe ...

  2. iOS 自定义控件开发(上)

    工作需要,最近在进行iOS方面的图表工作.找了很多第三方库都无法实现效果,所以决定自己写一个控件. <iOS 自定义控件开发(上)> <iOS 自定义控件开发(中)> #0 目 ...

  3. iOS部分页面横屏显示

    在iOS系统支持横屏顺序默认读取plist里面设置的方向(优先级最高)等同于Xcode Geneal设置里面勾选application window设置的级别次之 然后是UINavigationcon ...

  4. 李洪强iOS经典面试题上

    李洪强iOS经典面试题上     1. 风格纠错题 修改完的代码: 修改方法有很多种,现给出一种做示例: // .h文件 // http://weibo.com/luohanchenyilong/ / ...

  5. 毫无保留开源我写的:IOS Android Ipad 多点触摸通用js 库

    毫无保留开源我写的:IOS Android Ipad 多点触摸通用js 库 在线演示地址: http://m.yunxunmi.com/ 支持 IOS Android Ipad 等不同操作系统的手持或 ...

  6. 在iOS App的图标上显示版本信息

    最近读到一篇文章(http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/)介绍了一种非 ...

  7. IOS开发中UIBarButtonItem上按钮切换或隐藏实现案例

    IOS开发中UIBarButtonItem上按钮切换或隐藏案例实现案例是本文要介绍的内容,这个代码例子的背景是:导航条右侧有个 edit button,左侧是 back button 和 add bu ...

  8. 不推荐在iOS的浏览器应用上使用click和mouseover

    iOS上的Safari也支持click 和mouseover等传统的交互事件,只是不推荐在iOS的浏览器应用上使用click和mouseover,因为这两个事件是为了支持鼠标点击而设计 出来的.Cli ...

  9. IOS 横屏中添加UIImagePickerController获取系统图片

    今天写ipad的项目,然后需要调用系统相册选择图片,然后用了UIImagePickerController ,崩溃了,后来查了一下,UIImagePickerController只支持竖屏,但是... ...

随机推荐

  1. Oracle > count(*) / count(0) / count(1) | order by 1, 2

    select count(*), select count(0), select count(1) from table 在统计表的行数时候,经常用到 select count(*) 然而对于行数很多 ...

  2. SCADA软件整体架构

    SCADA软件整体框架如下所示: 1.免费版本可以支持的IO容量为2048点,无运行时间限制. 2.免费版本仅支持本地Runtime运行,CLServer服务器只能运行24小时. 3.免费版本支持的驱 ...

  3. oracle 分组排序

    SELECT * FROM (SELECT A.*, RANK() OVER(PARTITION BY A.DR_ATP_ID, A.AT_CODE ORDER BY A.KEY_CODE) RANK ...

  4. WEB架构师成长之路-架构师都要懂哪些知识 转

    Web架构师究竟都要学些什么?具备哪些能力呢?先网上查查架构师的大概的定义,参见架构师修炼之道这篇文章,写的还不错,再查查公司招聘Web架构师的要求. 总结起来大概有下面几点技能要求: 一. 架构师有 ...

  5. 【转】Android开发20——单个监听器监听多个按钮点击事件

    原文网址:http://woshixy.blog.51cto.com/5637578/1093936 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律 ...

  6. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.3.7

    For every matrix $A$, the matrix $$\bex \sex{\ba{cc} I&A\\ 0&I \ea} \eex$$ is invertible and ...

  7. java jvm学习笔记七(jar包的代码认证和签名)

    欢迎装载请说明出处:http://blog.csdn.net/yfqnihao 前言: 如果你循序渐进的看到这里,那么说明你的毅力提高了,jvm的很多东西都是比较抽像的,如果不找相对应的代码来辅助理解 ...

  8. Mtom Encoding in WCF

    http://www.codeproject.com/Articles/632101/Mtom-Encoding-in-WCF http://msdn.microsoft.com/zh-cn/libr ...

  9. Appium原理

    Appium原理小结 Api接口调用selenium的接口,android底层用android的instrumentation(API2.3+ 通过绑定另外一个独立的selendroid项目来实现的) ...

  10. IGT一道笔试题

    1到n连续的n个数 输入m 得出m个有序序列 比如 输入为n=5 ,m=3 则输出 543 542 541 532 531 521  432 431 421 321 当前长度为i,每个位上的取之范围为 ...