繁体   English   中英

iOS 11 UIImagePickerController奇怪的问题

[英]iOS 11 UIImagePickerController strange issue

我正在使用UIImagePickerController从照片库中选择单个图像。 iPad在横向模式下存在一个奇怪的问题。

推荐使用iPad上的UIPopoverPresentationController呈现图像选择器。 首次显示时,状态栏是正确的:

在此处输入图片说明

但是,进入照片库的第二层时,状态栏将更改为纵向模式:

在此处输入图片说明

到目前为止,我注意到的是:

  1. 此问题仅出现在iOS 11中,而不出现在iOS 10中。
  2. 发生这种情况时,将iPad旋转至纵向,然后再旋转至横向,将固定状态栏的方向。
  3. 它只是在第一次出现选择器控制器时才发生。
  4. 如果忽略,则将以纵向模式显示其他模式视图:

在此处输入图片说明

呈现uiimagepickerController的代码如下:

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationPopover;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;

    [self presentViewController:picker animated:YES completion:nil];

    UIPopoverPresentationController *popupController = picker.popoverPresentationController;
    if (popupController) {
        popupController.barButtonItem = sender;
    }

知道我做错了什么,还是一个错误?

整个示例项目可以在这里下载: https : //www.dropbox.com/s/zgipclyr0mz26c6/test.zip?dl=0

我终于找到了造成我问题的原因。

我的应用程序需要支持iPad上的所有方向和仅iPhone上的纵向模式。 因此,我添加了以下UIApplicationDelegate代码:

- (UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (window.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        return UIInterfaceOrientationMaskAll;
    }

    return UIInterfaceOrientationMaskPortrait;
 }

但是有时它会给我零个窗口,例如在iPad上使用UIPopoverPresentationController呈现的UIImagePickerController的情况下,它将返回UIInterfaceOrientationMaskPortrait并导致状态栏旋转为纵向模式。 我还注意到,只有在选中UIRequiresFullScreen时才会发生这种情况。

我通过检查窗口是否为nil来解决我的问题,如下所示:

- (UIInterfaceOrientationMask) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (window) {
        if (window.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
            return UIInterfaceOrientationMaskAll;
        } else {
            return UIInterfaceOrientationMaskPortrait;
        }
    } else {
        return UIInterfaceOrientationMaskAll;
    }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM