【发布时间】:2021-03-20 00:51:33
【问题描述】:
使用this 问题我要求用户决定是要使用相机还是从手机中选择图像:
//Show alert to select the media source type.
private func showAlert() {
let alert = UIAlertController(title: "Image Selection", message: "From where you want to pick this image?", preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: {(action: UIAlertAction) in
self.imagePicker.sourceType = .camera
}))
alert.addAction(UIAlertAction(title: "Photo Album", style: .default, handler: {(action: UIAlertAction) in
self.imagePicker.sourceType = .photoLibrary
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .destructive, handler: nil))
self.present(alert, animated: true, completion: nil)
}
我在viewDidLoad 中这样呼吁:
override func viewDidLoad() {
super.viewDidLoad()
firstTextField.delegate = self
showAlert()
present(imagePicker, animated: true, completion: nil)
imagePicker.delegate = self
firstImageView.layer.cornerRadius = 8
}
但是,当我对此进行测试时,会弹出警报并选择照片库,但该库没有出现。我曾尝试使用viewDidAppear,但也没能奏效。没有错误出现,它只是隐藏警报并显示当前视图控制器。
【问题讨论】:
标签: ios swift photo-gallery