我还不擅长在代码中创建 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/