首页 > 解决方案 > 打开 UIImagePicker 后如何在 AR Kit 场景中保留节点

问题描述

当我之前添加的所有节点(例如)文本在打开照片库或相机以添加新的照片节点后消失时,我遇到了一个问题。有什么办法可以解决吗?我的警报代码:

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
    alert.addAction(UIAlertAction(title: "Add Text", style: .default , handler:{ (UIAlertAction) in
        self.addTextView.isHidden = false
        self.inputTextField.becomeFirstResponder()
    }))
    alert.addAction(UIAlertAction(title: "Choose from Library", style: .default , handler:{ (UIAlertAction) in
        alert.dismiss(animated: true, completion: nil)
        let picker = UIImagePickerController ()
        picker.delegate = self
        picker.allowsEditing = true
        picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.present (picker, animated: true , completion: nil)
    }))
    alert.addAction(UIAlertAction(title: "Take a Photo", style: .default , handler:{ (UIAlertAction) in
        alert.dismiss(animated: true, completion: nil)
        let picker = UIImagePickerController ()
        picker.delegate = self
        picker.allowsEditing = true
        picker.sourceType = UIImagePickerControllerSourceType.camera
        self.present (picker, animated: true , completion: nil)
    }))
    alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler:{ (UIAlertAction) in
        // ACTION
    }))

    self.present(alert, animated: true, completion: nil)

标签: iosswiftarkit

解决方案


您的问题不在于您的警报,而在于您正在呈现另一个视图 - 离开 AR 场景。

这没关系,但是当您返回视图时,您的 AR 场景可能会被重新加载,可能是通过 viewWillAppear 中调用的东西或类似的东西。

检查一下,如果不是这样,请从您的生命周期覆盖(viewDidLoad、viewDidAppear、viewWillAppear)中发布代码 - 因为显示警报不会导致此错误。


推荐阅读