【问题标题】:Present UIImagePickerController inside a modal view or form sheet in iOS 7?在 iOS 7 的模态视图或表单中显示 UIImagePickerController?
【发布时间】:2014-02-08 22:33:26
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: ios7 uiimagepickercontroller modalviewcontroller


    【解决方案1】:

    表单是一种模态展示类型。您可以通过在演示之前修改视图控制器的 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];
    

    【讨论】:

    • 啊哈,我明白了,里奥·纳坦!好的,好吧,我正试图让它在我的弹出框内按我想要的方式工作,但是启动它的按钮不在栏上(它在表格视图静态单元格中)并且我的弹出框箭头无法正常工作。我会继续努力的。我的弹出框问题列在这里:stackoverflow.com/questions/21652296/…
    • @Kent 在此处查看我对您问题的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 1970-01-01
    相关资源
    最近更新 更多