我已经在我的应用程序中添加了一个相机和照片库,但我想要做的是当有人选择相机、拍照并选择它时,我希望它将用户引导到一个新的 View Controller 和在那里显示图像而不是在按钮所在的当前 View 上?
我在 Google 上进行了搜索,但没有发现任何清晰或快速的内容,而且由于我不了解 ObjC,所以我不确定我所看到的是否正确!
下面是我当前的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Camera(sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera;
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
}
@IBAction func Images(sender: AnyObject) {
let imageLoad = UIImagePickerController()
imageLoad.delegate = self
imageLoad.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imageLoad.allowsEditing = false
self.presentViewController(imageLoad, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image:UIImage, editingInfo: [String : AnyObject]?) {
self.dismissViewControllerAnimated(true, completion: nil)
最佳答案
根据上面的回答,你试图将图像设置为 ImageView ,当你应该尝试将图像设置为 ImageView 的图像时,所以,它应该是:
func viewDidLoad() {
super.viewDidLoad()
// Because the self.image is an optional var, you need to unwrap it
if let image = self.image {
self.imageView.image = self.image
}
}
关于ios - 选择/拍摄后如何将图像从相机/相机胶卷传递到新 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34229507/