gpt4 book ai didi

ios - 如何使用点击手势从 UIImageView 显示 UIImagePickerController

转载 作者:行者123 更新时间:2023-11-29 01:36:32 25 4
gpt4 key购买 nike

我希望 View 加载默认图像,并让用户点击该图像以从照片库中选择另一个图像。我这样做了,但是点击手势不起作用,我做错了什么?

class ProfileViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {

let imagePicker = UIImagePickerController()
@IBOutlet var profilePicture: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()

let tap = UITapGestureRecognizer(target: self, action: Selector("selectProfilePicture"))
profilePicture.addGestureRecognizer(tap)

imagePicker.delegate = self
}

func selectProfilePicture() {

imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)

}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {

self.dismissViewControllerAnimated(true, completion: nil)
profilePicture.image = image

}
}

最佳答案

尝试在您的 UIImageView 上启用 userInteractionEnabled:

profilePicture.userInteractionEnabled = true

关于ios - 如何使用点击手势从 UIImageView 显示 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32909079/

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