gpt4 book ai didi

IOS Swift imagePickerController 不调用

转载 作者:行者123 更新时间:2023-11-30 11:19:11 26 4
gpt4 key购买 nike

class MyPage: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {

var imagePicker = UIImagePickerController()
@IBOutlet weak var selectImage: UIButton!

override func viewDidLoad() {
imagePicker.sourceType = .photoLibrary
imagePicker.delegate = self
}



@IBAction func selectImage(_ sender: Any) {
print("a")
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
print("b")
imagePicker.allowsEditing = false
imagePicker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
self.present(imagePicker, animated: true,completion: nil)
}
@objc func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.dismiss(animated: true, completion: { () -> Void in
print("dismiss")
})

print(image)
selectImage.setImage(image, for: .normal)
}
}

如果触摸按钮打印 a 和 b 并弹出 photoLibrary

但是选择照片不调用imagePickerController

选择照片后不执行任何操作

如何在 swift 4 中使用 imagepicker?

最佳答案

Delegate 方法和 delegate 方法中删除 @objc 是这样的,所以用这个替换你的函数:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])

并使用以下方法获取图像:

guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {return}

关于IOS Swift imagePickerController 不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51471062/

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