获取手机照片UIImagePickerViewController
来源:互联网 发布:好的软件推荐 编辑:程序博客网 时间:2024/06/10 23:31
iPad与iPhone调用UIImagePickerViewController方法略有不同是本文要介绍的内容,文中很详细的讲述了iPad与iphone各自的调用方法,来看详细内容。
我们知道,在iPhone中获取照片库常用的方法如下:
- UIImagePickerController *m_imagePicker = [[UIImagePickerController alloc] init];
- if ([UIImagePickerController isSourceTypeAvailable:
- UIImagePickerControllerSourceTypePhotoLibrary]) {
- m_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- m_imagePicker.delegate = self;
- // [m_imagePicker.navigationBar.subviews];
- [m_imagePicker setAllowsEditing:NO];
- //m_imagePicker.allowsImageEditing = NO;
- [self presentModalViewController:m_imagePicker animated:YES];
- [m_imagePicker release];
- }else {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:
- @"Error accessing photo library!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
这对iPhone的操作是没有问题的。但是当我们在iPad环境中却有问题了,当我们运行时会报如下错误:
- Terminating app due to uncaught exception 'NSInvalidArgumentException',
- reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController'
所以我们必须通过UIPopoverController来实现才行。具体实现如下:
- UIImagePickerController *m_imagePicker = [[UIImagePickerController alloc] init];
- if ([UIImagePickerController isSourceTypeAvailable:
- UIImagePickerControllerSourceTypePhotoLibrary]) {
- m_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
- m_imagePicker.delegate = self;
- [m_imagePicker setAllowsEditing:NO];
- UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:m_imagePicker];
- self.popoverController = popover;
- //popoverController.delegate = self;
- [popoverController presentPopoverFromRect:CGRectMake(0, 0, 300, 300) inView:self.
- view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
- //[self presentModalViewController:m_imagePicker animated:YES];
- [popover release];
- [m_imagePicker release];
- }else {
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Error accessing photo library!"
- delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
这里需要注意,对局部UIPopoverController对象popover我们赋给了一个全局的UIPopoverController对象popoverController。而不能直接调用popover。因为在popover对象还可见时,是不能够被释放的。
0 0
- 获取手机照片UIImagePickerViewController
- 获取手机照片
- UIImagePickerViewController
- uiimagePickerViewController
- android 下获取手机所有照片
- iOS获取手机里的照片
- 获取手机系统中的所有照片
- IOS开发获取手机内照片属性
- android 下获取手机所有照片
- Android笔记之获取手机图库照片和拍照获取照片
- 关于三星手机拍照 获取的照片旋转处理
- 三星手机拍照翻转获取照片的问题
- 调用手机相机拍照并获取拍摄的照片
- 转自@CrazyCodeBoy 获取手机相册并选择照片
- 转自@CrazyCodeBoy 获取手机相册并选择照片
- 如何从手机相册或相机获取照片
- iOS---如何获取手机的本地照片和相册
- html5本地拍照获取照片在手机中路径
- IPickerView
- fedora 22 截图
- PHP面向对象1.1简单的介绍
- ubuntu 安装 Cmake
- Java Servlet原理学习(二)
- 获取手机照片UIImagePickerViewController
- 三顾招聘会
- UITabBarController
- Connection cannot be null when 'hibernate.dialect' not set
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- 《奔跑吧,胖鸟》消清新简单跑酷游戏,看你能闯几关
- LLDB help 菜单
- Unity Assets目录下的特殊文件夹名称
- 如何选择AFNetworking版本