【发布时间】:2019-04-21 16:45:06
【问题描述】:
在 Xcode 10.1 中创建项目,设备方向横向仅左右。
在 Plist 中添加了以下 Key
隐私 - 相机使用说明:“用于拍照”
import UIKit
class UploadViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate
{
//MARK:- ViewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func cameraButtonAction(_ sender: UIButton)
{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .camera
imagePicker.modalPresentationStyle = .overCurrentContext
imagePicker.delegate = self
self.present(imagePicker, animated: true, completion: nil)
}else{
let alert = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
以上代码在以下设备中运行良好
iPhone 8 (iOS 12)
iPhone 7 (iOS 11.4.1)
iPad mini (iOS 11)
但是当我在 iOS 12.1 的 iPhoneX 上运行它时,出现以下错误。
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [CAMViewfinderViewController shouldAutorotate] is returning YES'
*** First throw call stack:
libc++abi.dylib: terminating with uncaught exception of type NSException
我对这个问题进行了研究,但我还没有找到解决方案。 以下是我为相关问题找到的几个链接,但没有一个适用于 iPhoneX 的答案。
Using UIImagePickerController in landscape orientation
【问题讨论】:
-
@Anbu.karthik:感谢您的回复,但该解决方案不起作用。
标签: ios iphone swift iphone-x ios12