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

标签 ios7 uiimagepickercontroller modalviewcontroller

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

在我的 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];

现在我该怎么做才能创建模态视图或表单并在其中显示图像选择器?

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

最佳答案

表单是一种模式表示类型。您可以通过在呈现之前修改 View Controller 的 modalPresentationStyle 属性来更改它。

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

但是,如果您阅读documentation of UIImagePickerController ,您将看到 Apple 要求您在弹出窗口内呈现 View Controller

所以:

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

关于ios7 - 在 iOS 7 中的模态视图或表单中显示 UIImagePickerController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652632/

相关文章:

iphone - 我可以从 iPhone 中的照片中获取图像的名称吗

objective-c - 如何呈现完全一样的 View ?

iphone - 显示模态视图

objective-c - 弹出一个以模态方式呈现的 UINavigationController

ios - iPhone日期格式

ios - 如何使用一个数组作为另一个数组的谓词?

ios - 在一个应用程序中组合不同的 View

iphone - 如何使用覆盖层允许在相机上点击对焦

ios - 向 UIImagepickercontroller 导航栏添加后退按钮

ios - 如何计算 iOS 7 中的实际字体磅值(不是边界矩形)?