本文介绍了仅关闭 ImagePicker 并将图像传递给 ScrollViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ImagePicker,它在 ScrollViewController 出现后显示 (1).

I have an ImagePicker that is displayed after a ScrollViewController is presented (1).

问题:

ImagePicker 中选取图像后,我如何关闭只是 ImagePicker 以便显示 ScrollViewController 然后将选取的图像传递给ScrollViewController?

(1) 呈现 ScrollViewControllerImagePicker

(1) Presenting ScrollViewController and 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 关闭后

Handling ImagePicker after it is closed

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        let myImage = info[UIImagePickerControllerOriginalImage] as! UIImage

//How to send myImage to the ScrollViewController and close ImagePicker?

}

推荐答案

MyImagePickerController

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)
}

这篇关于仅关闭 ImagePicker 并将图像传递给 ScrollViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 07:46