func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let originalImage = info["UIImagePickercontrollerOriginalImage"] {
print(originalImage.size)
}
}
xCode
给我错误
“歧义使用'size'”
有什么帮助吗?
答案 0 :(得分:0)
您有两个问题:
originalImage
是AnyObject
,而不是UIImage
。didFinishPickingMediaInfo
签名错误。您的固定代码为:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let originalImage = info["UIImagePickercontrollerOriginalImage"] as? UIImage {
print(originalImage.size)
}
}
答案 1 :(得分:0)
我建议使用Swift 5.0的代码---> func imagePickerController(_ picker:UIImagePickerController,didFinishPickingMediaWithInfo info:[UIImagePickerController.InfoKey:Any]){
if let originalImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
print(originalImage.size)
}
}
答案 2 :(得分:-1)
您需要
if let originalImage = info["UIImagePickercontrollerOriginalImage"] as? UIImage {--}
info
是[String : AnyObject]
,因此您需要将AnyObject
强制转换为UIImage