簡體   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