【问题标题】:ios 10 Snapshotting a view that has not been rendered results in an empty snapshotios 10 对尚未渲染的视图进行快照会导致快照为空
【发布时间】:2017-02-23 22:08:36
【问题描述】:

this question ask again 但我找不到 ios 10

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)
 {
            self.imagePicker.delegate = self
            self.imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
            self.imagePicker.allowsEditing = false
            self.imagePicker.cameraCaptureMode = .photo
            //self.imagePicker.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
            self.present(self.imagePicker, animated: true, completion: nil)
            self.imagePicked.isUserInteractionEnabled = true

 }
else
 {
            print("No Camera")
 }

对尚未渲染的视图进行快照会导致空白 快照。确保您的视图之前至少渲染过一次 屏幕更新后的快照或快照。

当我旋转相机并拍摄时,就会出现此错误。

【问题讨论】:

    标签: camera uiimagepickercontroller swift3 ios10


    【解决方案1】:

    自我解决方案像魅力一样为我工作 :-) 希望它对所有人都有帮助

    DispatchQueue.global(qos: .userInitiated).async
    {
         self.present(self.imagePicker, animated: true, completion: nil)
    
    }
    

    【讨论】:

      【解决方案2】:

      我收到了错误

      此应用程序正在从后台线程修改自动布局引擎,这可能导致引擎损坏和奇怪的崩溃...

      使用 DispatchQueue.main.async 代替对我有用。

      【讨论】:

        【解决方案3】:

        此行为不限于 UIImagePickerController。下面是一个 UIViewController 的示例,它以模态方式呈现另一个 UIViewController。在第二个 UIViewController 中,启动 Safari 以显示 URL,从而触发相同的错误消息,“Cannot snapshot view (>) with afterScreenUpdates:NO, because the view is not in a window. Use afterScreenUpdates:YES.”

        我还没有找到任何抑制消息的方法,但在我的应用程序中它没有害处。我认为这里发生的情况是,一些 Apple 代码正在拍摄应用程序视图层次结构的快照,但在拍摄快照之前尚未呈现键盘(由单独的 UIWIndow 拥有)。

        /* Generates the error message:
        
         Cannot snapshot view (<UIKeyboardImpl: 0x7f82ded12ea0; frame = (0 0; 414 271); layer = <CALayer: 0x610000035e20>>) with afterScreenUpdates:NO, because the view is not in a window. Use afterScreenUpdates:YES.
        
         ... after the "Now Tap Me, For Glory!" label is clicked
        */
        
        import UIKit
        
        class ViewController: UIViewController {
        
            override func viewDidLoad() {
                super.viewDidLoad()
        
                let input = UITextField()
                input.placeholder = "Tap here first -- to bring up keyboard"
                input.frame = CGRect(x: 10, y: 50, width: 300, height: 20)
                view.addSubview(input)
        
                let button = UIButton()
                button.setTitleColor(UIColor.blue, for: .normal)
                button.setTitle("Then tap here", for: .normal)
                button.addTarget(self,
                                 action: #selector(buttonPushed),
                                 for: .touchUpInside)
                button.frame = CGRect(x: 10, y: 80, width: 200, height: 20)
                view.addSubview(button)
            }
        
            func buttonPushed() {
                let modalVC = ModalViewController()
                present(modalVC, animated: true, completion: nil)
            }
        }
        
        class ModalViewController: UIViewController {
        
            override func viewDidLoad() {
                super.viewDidLoad()
                view.backgroundColor = UIColor.white
                let label = UILabel()
                label.text = "Now Tap Me, For Glory!"
                label.frame = CGRect(x: 10, y: 50, width: 300, height: 20)
                view.addSubview(label)
                label.isUserInteractionEnabled = true
                label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(labelTapped)))
            }
        
            func labelTapped() {
                UIApplication.shared.open(URL(string: "http://planetbeagle.com")!, options: [:], completionHandler: { _ in
                        self.dismiss(animated: true, completion: nil) })
            }
        }
        

        【讨论】:

        • 与问题没有直接关系,但如果您使用的是 iOS,您可能需要考虑“点击”而不是“点击”。
        • @buildsucceeded 呵呵,不是所有的iOS开发者都在(可点击的)模拟器中运行这个吗? ;-) 尽管如此,我已经屈服于你施加的同伴压力!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-08
        • 2013-09-24
        • 1970-01-01
        • 2020-06-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多