【发布时间】:2023-03-04 09:27:01
【问题描述】:
我使用这两个单独的按钮来打开相机或 imageGallery。
@IBAction func tapGal(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
} else {
NSLog("No Cam Fam")
}
}
@IBAction func tapCam(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
} else {
NSLog("No Cam Fam")
}
}
“相机”按钮正常工作,这意味着它会打开相机,但图库按钮也会打开相机。我已经仔细检查以确保图库按钮实际上链接到 tapGal 函数。我也试过用.photoLibrary替换.savedPhotosAlbum,但结果是一样的。
【问题讨论】:
-
请仔细查看您的代码。查看
imagePicker.sourceType = ...的两条线。 -
你的代码是一样的,所以结果是一样的。
标签: ios swift camera uiimagepickercontroller gallery