gpt4 book ai didi

ios - 如何使用 swift 4 通过 Image Picker Controller 发送图像数据

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

enter image description here我有 tabbarControllerCameraViewController。单击相机选项卡后,我想显示相机。我已经做了。打开相机后,我想将选择的特定图像显示到下一个 viewController,但无法执行。我正在使用 UIImagePickerController,请帮忙

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let tabBarIndex = tabBarController.selectedIndex
if tabBarIndex == 0 {
//do your stuff
print("First Tab")
} else if tabBarIndex == 1 {
print("Second Tab")
} else if tabBarIndex == 2 {
//do the camera stuff here
let imagePickerController1 = ImagePickerController()
imagePickerController1.delegate = self
imagePickerController1.imageLimit = 2
present(imagePickerController1,animated: true,completion: nil)
print("camera")
print("Third Tab")
}
}

完成按钮按下代码。

func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
let firstVC = self.storyboard!.instantiateViewController(withIdentifier: "CameraVC") as! CameraVC

show(firstVC, sender: nil)
dismiss(animated: true, completion: nil)
print("done")
}



func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info["UIImagePickerControllerOriginalImage"] as? UIImage {

}
dismiss(animated: true, completion: nil)
}

最佳答案

您的doneButtonDidPress 方法是在TabBarController 中实现的,您希望在CameraVC 中选择Images 所以做1 件事添加CameraVC 中的 NotificationCenter 并在完成 Image 后使用 Images array 发布该通知挑选。并从 CameraVC 中的 array 加载选定的 images

相机VC

NotificationCenter.default.addObserver(self, selector: #selector(updateSelectedImages(_:)), name: NSNotification.Name(rawValue: "updateSelectedImages"), object: nil)


@objc func updateSelectedImages(_ notification: Notification) {
let imagesInfo = notification.object as? NSDictionary

self.arrImages = imagesInfo?.value(forKey: "selectedIamges") as! [UIImage]
self.imageView.image = self.arrImages[0]
self.imageView1.image = self.arrImages[1]
}

UITabBarController

let dict = NSMutableDictionary()
dict.setValue(images, forKey: "selectedIamges")
NotificationCenter.default.post(name: NSNotification.Name("updateSelectedImages"), object: dict)

关于ios - 如何使用 swift 4 通过 Image Picker Controller 发送图像数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49999322/

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