有没有办法从模态视图中present
和UIImagePickerController
?
在我的情况下,我有一个称为class
的MakeWishView
,它是一个UIView
,如果用户在button
内点击MakeWishView
,则用户应该可以选择图像。我现在的问题是我无法调用present
,因为MakeWishView
不是ViewController
而是UIView
。
这是我想称呼的:
@objc private func wishImageButtonTapped(){
showImagePickerController()
print("wishImageButtonTapped")
}
// image picker
extension MakeWishView: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@objc func showImagePickerController(){
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil) // -> error
}
}
最佳答案
将代表添加到正在呈现的vc中,例如
class MakeWishView:UIView {
weak var delegate:VCName?
要么
let root = (UIApplication.shared.delegate as! AppDelegate).window!.rootViewController
root.present(imagePickerController, animated: true, completion: nil)
关于ios - Swift-从模态视图访问UIImagePickerController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59724557/