[英]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.