我已经多次查看此代码,即使是一个小时,但我可以找到错误。
编译项目没有错误,完全没有错误显示,但是我无法选择图像,当我按下UIImage时,什么也没发生。
注册时“signUp View Controller”中有类似代码一切顺利,可以选择(pick)图片,图片正确保存在Firebase上。
此外,在这个“ProfileTableViewController”中,一切都显示得很好,Firebase 上保存的图像已加载并显示在 Profile View 中,但无法选择(按下它)来选择和更改。
其他一切都经过测试、更改和保存(用户名甚至电子邮件),只有图像给我带来了问题。你能看看代码并告诉我我做错了什么吗?
谢谢。
import UIKit
class ProfileTableViewController: UITableViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var profileImage: UIImageView!
@IBOutlet weak var username: UITextField!
@IBOutlet weak var email: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Edit Profile"
let tap = UITapGestureRecognizer(target: self, action: #selector(ProfileTableViewController.selectPhoto(_))
tap.numberOfTapsRequired = 1
profileImage.addGestureRecognizer(tap)
profileImage.layer.cornerRadius = profileImage.frame.size.height / 2
profileImage.clipsToBounds = true
if let user = DataService.dataService.currentUser {
username.text = user.displayName
email.text = user.email
if user.photoURL != nil {
if let data = NSData(contentsOfURL: user.photoURL!) {
self.profileImage!.image = UIImage.init(data: data)
}
}
} else {
// No user is signed in
}
}
func selectPhoto(tap: UITapGestureRecognizer) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
imagePicker.sourceType = .Camera
} else {
imagePicker.sourceType = .PhotoLibrary
}
self.presentViewController(imagePicker, animated: true, completion: nil)
}
// UIImagePicker Delegate
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
profileImage.image = image
dismissViewControllerAnimated(true, completion: nil)
}
你需要在 UIImageView 上启用用户交互,添加手势识别后试试这个:
profileImage.userInteractionEnabled = true
关于ios - 快速图像选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38364104/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |