如何将ImagePicker放入视图容器中?

时间:2016-02-26 19:49:00

标签: ios swift

[编辑]:我通过简单地调用addSubview来实现它。还使用约束将其正确放置在我的容器视图中。但是,单击按钮拍摄照片或反转相机不起作用。有什么建议吗?

我正在使用https://github.com/hyperoslo/ImagePicker,我想将其嵌入视图容器中。所以我在storyboard中添加了一个容器视图,它自动创建了一个UIViewController供我嵌入使用。我已经为新的UIViewController分配了一个类,并尝试在其中添加imagePickerController:

class mainViewController: UIViewController {
   @IBOutlet weak var containerView: UIView!

   ....
}


class containerViewController: UIViewController, ImagePickerDelegate {
    lazy var imagePickerController: ImagePickerController = ImagePickerController()

    func wrapperDidPress(images: [UIImage]) {
        print("wrapperDidPress")
    }
    func doneButtonDidPress(images: [UIImage]) {
        print("doneDidPress")
    }

    func cancelButtonDidPress() {
        print("cancelDidPress")
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)

        self.addChildViewController(imagePickerController)
        imagePickerController.didMoveToParentViewController(self)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        imagePickerController.delegate = self
    }
}

结果我只得到一个没有ImagePicker的空容器视图。我错过了什么?

0 个答案:

没有答案