UIImagepicker不适用于iphone应用程序的ipad

时间:2015-08-10 13:15:49

标签: ios iphone ipad uiimagepickercontroller

我正在开发一款iPhone应用程序,在我的应用程序中,有些页面必须从图库中获取图像。所有工作在iPhone和iPad上都很好,但我不能总是通过imagePickerControllerDidCancel()获得图像。

此方法仅在我选择图像时触发事件..我无法找到任何解决方案。

任何帮助都会非常明显!

   if (!self.takeImage) self.takeImage = [[UIImagePickerController alloc]init];
        [[self.takeImage navigationBar] setTintColor:[UIColor blackColor]];

   self.takeImage.sourceType = UIImagePickerControllerSourceTypeCamera;
   self.takeImage.delegate = self;

   [self presentViewController:self.takeImage animated:YES completion:nil];

2 个答案:

答案 0 :(得分:0)

您需要在iPad上添加UIPopoverController以显示UIImagePickerController

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
    [popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popOver = popover;
} else {
    [self presentModalViewController:picker animated:YES];
}

答案 1 :(得分:0)

如果您的ipad iOS版本低于7.0,则可能会出现问题。尝试使用presentPopoverFromRect:而不是presentViewController。

在这里,这段代码可能有所帮助,

if (([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) && SYSTEM_VERSION_LESS_THAN(@"7.0")) 
{
        self.popOver = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        [self.popOver presentPopoverFromRect:CGRectMake(0.0, 0.0, 600.0,500.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny
                                    animated:YES];
    }
    else
        [self presentViewController:imagePickerController animated:YES completion:nil];