UIImagePickerController Gallery 委托未调用
UIImagePickerController Gallery delegate is not calling
我在这段代码中使用 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)
}
相机代理工作正常,但画廊代理不工作。对于相机,我在 class 中定义了 "picker" 变量,并在 "Viewdidload" 中定义了它的委托自身。我也尝试在 openGallary 函数中使用选择器变量,但它也不起作用。
我认为这两行可能会有所帮助:
menuViewController.delegate = self
menuViewController.sourceType = .PhotoLibrary
确保您已将 UINavigationControllerDelegate
和 UIImagePickerControllerDelegate
添加到您的 ViewController
。
我在这段代码中使用 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)
}
相机代理工作正常,但画廊代理不工作。对于相机,我在 class 中定义了 "picker" 变量,并在 "Viewdidload" 中定义了它的委托自身。我也尝试在 openGallary 函数中使用选择器变量,但它也不起作用。
我认为这两行可能会有所帮助:
menuViewController.delegate = self
menuViewController.sourceType = .PhotoLibrary
确保您已将 UINavigationControllerDelegate
和 UIImagePickerControllerDelegate
添加到您的 ViewController
。