gpt4 book ai didi

xcode - Swift 3 - 无法覆盖 'imagePickerController'

转载 作者:行者123 更新时间:2023-11-28 09:31:02 24 4
gpt4 key购买 nike

我的代码:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
self.image = image
self.imageStatusLabel.text = "There is a picture"
self.imageStatusLabel.textColor = UIColor.blue()

picker.dismiss(animated: true, completion: nil)
}

这是错误:

Cannot override 'imagePickerController' which has been marked unavailable: APIs deprecated as of iOS 7 and earlier are unavailable in Swift

好吧,我尝试使用更新的函数:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
// But no image in the parameters
}

但是,参数中没有图像,我可以获取图像。
我该怎么办?

最佳答案

您必须使用 info 参数并强制转换为 UIImage .不要忘记你必须在 Privacy - Photo Library Usage Description 中输入“Privacy - Camera Usage Description”和“info.plist”文件并用字符串填充值,解释请求访问照片库和相机的原因。

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
pictureImageView.contentMode = .scaleToFill
pictureImageView.image = pickedImage
}

picker.dismiss(animated: true, completion: nil)
}

关于xcode - Swift 3 - 无法覆盖 'imagePickerController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37895049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com