Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 图像选择器取消后,输入附件视图消失[Swift]_Ios_Swift_Uiimagepickercontroller_Inputaccessoryview - Fatal编程技术网

Ios 图像选择器取消后,输入附件视图消失[Swift]

Ios 图像选择器取消后,输入附件视图消失[Swift],ios,swift,uiimagepickercontroller,inputaccessoryview,Ios,Swift,Uiimagepickercontroller,Inputaccessoryview,我有一个非常标准的inputAccessoryView,带有图像和相册按钮。但我发现,如果相册是在显示键盘时启动的(换句话说,textView是第一个响应程序),inputAccessoryView会在相册关闭时消失。如何让它停留在屏幕底部 我的实现是通用的: let inputContainerView: UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 40) override var i

我有一个非常标准的
inputAccessoryView
,带有图像和相册按钮。但我发现,如果相册是在显示键盘时启动的(换句话说,
textView
是第一个响应程序),
inputAccessoryView
会在相册关闭时消失。如何让它停留在屏幕底部

我的实现是通用的:

let inputContainerView: UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 40)

override var inputAccessoryView: UIView? {
    return inputContainerView
}

lazy var imagePicker: UIImagePickerController = {
    let picker = UIImagePickerController()
    picker.delegate = self
    return picker
}()

// The function that is hooked up to the album button
func handleAlbum() {
    if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
        imagePicker.sourceType = .photoLibrary
        imagePicker.allowsEditing = false
        present(imagePicker, animated: true, completion: nil)
    }
}
下面是一个演示问题的gif。请注意,
inputAccessoryView
在最后消失了。非常感谢你


请尝试在图像选择器关闭后添加self.inputAccessoryView.becomeFirstResponder()。

我解决了这个问题。事实证明,在展示图像选择器之前,我需要让textView退出FirstResponder()。另外,添加以下代码。它处理用户取消拾取操作的情况

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    picker.dismiss(animated: true, completion: nil)
}
根据Apple文档:

代理对此方法的实现应该通过调用父视图控制器的
dismissModalViewControllerAnimated:
方法来关闭选择器视图

此方法的实现是可选的,但是预期的


dismissModalViewControllerAnimated:
方法已被弃用,应改为使用
dismissViewControllerAnimated:completion:

我遇到了完全相同的问题,但在uiimagepicker内的搜索栏上键入内容时仍然出现此错误,您能提供帮助吗?