gpt4 book ai didi

ios - 如何从 UIImagePickerController 导入图像到新的 VC? swift

转载 作者:行者123 更新时间:2023-11-30 13:51:53 25 4
gpt4 key购买 nike

我已经在我的应用程序中添加了相机和照片库,但我想做的是,当有人选择相机、拍照并选择它时,我希望它将用户引导到新的 View Controller 并显示那里的图像而不是按钮所在的当前 View 上?

到目前为止,从谷歌上的搜索来看,我已经设法在相机或库关闭时加载新 View ,但现在我似乎不知道如何将照片也导入新 View ?!

如果有人能提供帮助,那就太好了。

下面是我当前的代码:

    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 image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
image.allowsEditing = false


self.presentViewController(image, animated: true, completion: nil)



}



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

self.dismissViewControllerAnimated(true, completion: nil)
let svc = self.storyboard!.instantiateViewControllerWithIdentifier("imageViewer") as! ImageViewController
self.presentViewController(svc, animated: 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 - 如何从 UIImagePickerController 导入图像到新的 VC? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34161541/

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