在ImagePicker
出现后,我显示ScrollViewController
。
问题:
从
ImagePicker
中挑选图像后,我该如何解散 只是ImagePicker
,以便显示ScrollViewController
,然后将选中的图像传递给ScrollViewController
?
(1)展示ScrollViewController
和ImagePicker
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ScrollViewControllerID") as! ScrollViewController
self.presentViewController(vc, animated: true) {
let imagePicker = MyImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
vc.presentViewController(imagePicker, animated: true, completion: nil)
}
关闭后处理ImagePicker
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let myImage = info[UIImagePickerControllerOriginalImage] as! UIImage
//How to send myImage to the ScrollViewController and close ImagePicker?
}
答案 0 :(得分:0)
MyImagePickerController
class MyImagePickerController: ... {
var controller:ScrollViewController!
convenience init(controller: ScrollViewController) {
self.init()
self.controller = controller
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let myImage = info[UIImagePickerControllerOriginalImage] as! UIImage
controller.imageName = myImage
self.dismissViewControllerAnimated(true, completion: nil)
}
这就是你应用它的方式
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ScrollViewControllerID") as! ScrollViewController
self.presentViewController(vc, animated: true) {
let imagePicker = MyImagePickerController(controller: vc)
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
vc.presentViewController(imagePicker, animated: true, completion: nil)
}