我正在尝试上传图像,但首先我必须访问媒体库,但是我的代码不正确,更新的代码可以解决此错误?
类型'SignUpViewController'没有成员'handleSelectProfileImageView'
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(SIGNUPViewController.handleSelectProfileImageView))
ProfileImage.addGestureRecognizer(tapGesture)
ProfileImage.isUserInteractionEnabled = true
}
@objc func handleSelectProfileImageView () {
@IBAction func profileImageBtnAction(_ sender: Any) {
let alert:UIAlertController=UIAlertController(title: "Choose Image", message: nil, preferredStyle: UIAlertController.Style.actionSheet)
let cameraAction = UIAlertAction(title: "Camera", style: UIAlertAction.Style.default)
{
UIAlertAction in
self.openCamera()
}
let gallaryAction = UIAlertAction(title: "Gallery", style: UIAlertAction.Style.default)
{
UIAlertAction in
self.openGallary()
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel)
{
UIAlertAction in
}
// Add the actions
picker.delegate = self
alert.addAction(cameraAction)
alert.addAction(gallaryAction)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: nil)
}
func openCamera() {
if UIImagePickerController.isSourceTypeAvailable(.camera){
picker.allowsEditing = false
picker.sourceType = UIImagePickerController.SourceType.camera
present(picker, animated: true, completion: nil)
}else{
print("Simulator has no camera! So please run in real device which has camera")
}
}
func openGallary()
{
picker.allowsEditing = false
picker.sourceType = UIImagePickerController.SourceType.photoLibrary
present(picker, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
chosenImage = (info[UIImagePickerController.InfoKey.originalImage] as? UIImage)!
profileImageview.image = chosenImage
profileImageview.image = self.resizeImage(chosenImage)
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "dd-MM-YYYY hh:mm:ss"
let dateExtension = formatter.string(from: date)
let fileManager = FileManager.default
let paths = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent(dateExtension).appending(".png")
print(paths)
imagedata = chosenImage.jpegData(compressionQuality: 0.5)
fileManager.createFile(atPath: paths as String, contents: imagedata, attributes: nil)
profileImageview.layer.cornerRadius = profileImageview.frame.width/2
profileImageview.layer.masksToBounds = true
dismiss(animated: true, completion: nil)
}
//What to do if the image picker cancels.
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
Hope this will help your