[英]iOS 11 UIImagePickerController strange issue
我正在使用UIImagePickerController從照片庫中選擇單個圖像。 iPad在橫向模式下存在一個奇怪的問題。
推薦使用iPad上的UIPopoverPresentationController呈現圖像選擇器。 首次顯示時,狀態欄是正確的:
但是,進入照片庫的第二層時,狀態欄將更改為縱向模式:
到目前為止,我注意到的是:
呈現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.