UIImagePickerController 与 LongPressGesture 崩溃

UIImagePickerController crashes with LongPressGesture

今天我意识到我的 UIImagePickerController 在我使用它和一个按钮来显示它时工作正常。但是,当我想通过 LongPressGesture 显示它时,应用程序会在运行时崩溃。为什么会这样?

操作:

@IBAction func ppLongPressed(_ sender: UILongPressGestureRecognizer) {
    imagePicker.delegate = self
    imagePicker.sourceType = .photoLibrary
    present(imagePicker, animated: true, completion: nil)
}

代表:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        self.profileImage.image = image

    }
    dismiss(animated: true, completion: nil)
}

长手势有状态

@IBAction func ppLongPressed(_ sender: UILongPressGestureRecognizer) {
    if sender.state != .began { return }
    imagePicker.delegate = self
    imagePicker.sourceType = .photoLibrary
    present(imagePicker, animated: true, completion: nil)
}