首页 > 代码库 > 在iPad iOS8环境下打开相冊或者拍照

在iPad iOS8环境下打开相冊或者拍照

在iPad下打开相冊或者拍照,假设使用 UIImagePickerController 打开相冊或者拍照,那必需要用到 UIPopoverController 去打开。


UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
                self.popoverController = popover;
                [self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 600, 800) inView:self.viewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];


可是在iOS8的iPad环境下。却打不开相冊或者拍照,提演示样例如以下:

Warning: Attempt to present <UIImagePickerController: 0x7fb3d1167a00>  on <CubeWebViewController: 0x7fb3d324ad20> which is already presenting (null)


解决方法例如以下:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
                UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
                self.popoverController = popover;
                [self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 600, 800) inView:self.viewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            }];






參考:http://stackoverflow.com/questions/24942282/uiimagepickercontroller-not-presenting-in-ios-8


在iPad iOS8环境下打开相冊或者拍照