swift3 – Xcode 8 – swift 3:创建一个未知类型的图像格式是一
发布时间:2020-12-14 02:24:14 所属栏目:百科 来源:网络整理
导读:使用UI ImagePicker选择图像时出错: [Generic] Creating an image format with an unknown type is an error 我正在使用Xcode 8.1和Swift 3. 我已经搜遍了网络,但似乎没有解决我的问题,请帮忙! 这是我的代码: class TabBarController: UITabBarController
使用UI
ImagePicker选择图像时出错:
[Generic] Creating an image format with an unknown type is an error 我正在使用Xcode 8.1和Swift 3. 这是我的代码: class TabBarController: UITabBarController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { var isSelected: Bool = false var imgPicker: UIImagePickerController = UIImagePickerController() override func viewDidLoad() { super.viewDidLoad() //imgPicker = UIImagePickerController() imgPicker.delegate = self imgPicker.allowsEditing = false imgPicker.sourceType = .photoLibrary } func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediaWithInfo info: [String : Any]) { imgPicker.dismiss(animated: true,completion: nil) if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { self.performSegue(withIdentifier: "toPostPicture",sender: image) } } func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { dismiss(animated: true,completion: nil) } func askImagePickerSource(sender: UIViewController) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { let alert = UIAlertController(title: nil,message: nil,preferredStyle: .actionSheet) let cameraAction = UIAlertAction(title: "Camera",style: .default,handler: { (action: UIAlertAction) in self.imgPicker.sourceType = .camera self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .camera)! sender.present(self.imgPicker,animated: true,completion: nil) }) let photoLibraryAction = UIAlertAction(title: "Photo Library",handler: { (action: UIAlertAction) in self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! sender.present(self.imgPicker,completion: nil) }) let cancelAction = UIAlertAction(title: "Cancel",style: .cancel) { (UIAlertAction) in sender.dismiss(animated: true,completion: nil) } alert.addAction(cameraAction) alert.addAction(photoLibraryAction) alert.addAction(cancelAction) sender.present(alert,completion: nil) } else { self.imgPicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)! sender.present(self.imgPicker,completion: nil) } } override func prepare(for segue: UIStoryboardSegue,sender: Any?) { if segue.identifier == "toPostPicture" { if let postPictureVC = segue.destination as? PostPictureVC { if let image = sender as? UIImage { postPictureVC.image = image } } } } }
我通过不为UIImagePickerController添加委托作为’self’来面对同样的问题.添加后,我能够从图库中获取所选图像.但即使将委托添加为自己并能够访问图像(在ImageView上显示),我仍然得到相同的错误.经过对SO的进一步研究后,我发现这只是一个错误,不会以任何方式影响应用程序.
另见“Creating an image format with an unknown type is an error Objective-C Xcode 8” (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |