UIImagePickerController Gallery委托不调用

时间:2016-06-27 14:10:48

标签: swift uiimagepickercontroller

我正在使用带有此代码的UIImagePickerController

    func openCamera()
{
    if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
    {

        picker.allowsEditing = false
        picker.sourceType = UIImagePickerControllerSourceType.Camera
        picker.cameraCaptureMode = .Photo
        picker.modalPresentationStyle = .FullScreen
        presentViewController(picker,
                              animated: true, 
                              completion: nil)

    }
    else
    {
        openGallary()
    }
}
func openGallary()
{    
    let menuViewController =  UIImagePickerController()

    menuViewController.modalPresentationStyle = .Popover
    menuViewController.preferredContentSize = CGSizeMake(320, 320 )
    //menuViewController.tableView = FrontTable

    let popoverMenuViewController = menuViewController.popoverPresentationController
    popoverMenuViewController?.permittedArrowDirections = .Any
    popoverMenuViewController?.delegate = self
    popoverMenuViewController?.sourceView = flagBtn
    popoverMenuViewController?.sourceRect = CGRect(
        x: 15, 
        y: 25, 
        width: 1,
        height: 1)
    presentViewController(
        menuViewController,
        animated: true,
        completion: nil)

}


func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
     picker .dismissViewControllerAnimated(true, completion: nil)
  let image=info[UIImagePickerControllerOriginalImage] as? UIImage

    flagBtn.setImage(image, forState: .Normal)
    flagBtn.setImage(image, forState: .Highlighted)
    flagBtn.setImage(image, forState: .Selected)
}

随着相机委托工作正常,但画廊代表不工作。对于相机,我已经定义了"选择器"在类中变量并定义它的委托自我" Viewdidload"。我也尝试在openGallary函数中使用picker变量,但它也无法正常工作。

1 个答案:

答案 0 :(得分:0)

我认为这两行可能会有所帮助:

UINavigationControllerDelegate

确保您已将UIImagePickerControllerDelegateViewController添加到INTERVAL ? MINUTE