在iOS 7中的模态视图或表单中显示UIImagePickerController?

时间:2014-02-08 22:33:26

标签: ios7 uiimagepickercontroller modalviewcontroller

我不擅长在代码中创建视图,所以这可能是一个简单的问题。

在我的iPad应用程序中,我有这个图像选择器,我想将它呈现在屏幕中心的500x500模态视图中或表格中心屏幕中:

_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePicker.allowsEditing = NO;
_imagePicker.navigationBar.tintColor = [UIColor redColor];
_imagePicker.navigationBar.backgroundColor = [UIColor greenColor];

现在我该如何创建模态视图或表单并在其中显示图像选择器?

(我查看了许多示例和Q& A,但找不到简单的答案。感谢您的帮助!)

1 个答案:

答案 0 :(得分:2)

表单是一种模式表示类型。您可以通过在演示之前修改视图控制器的modalPresentationStyle属性来更改它。

_imagePicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:_imagePicker animated:YES completion:nil];

但是,如果您阅读documentation of UIImagePickerController,您会看到 Apple要求您在浏览器中显示视图控制器

所以:

if([_popoverController popoverVisible])
{
    [_popoverController dismissPopoverAnimated:NO];
    _popoverController = nil;
}
_popoverController = [[UIPopoverController alloc] initWithContentViewController:_imagePicker];
[_popoverController setDelegate:self];
[_popoverController presentPopoverFromBarButtonItem:_button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];