首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ios 10快照未呈现为空快照的视图

ios 10快照未呈现为空快照的视图
EN

Stack Overflow用户
提问于 2016-10-14 12:57:38
回答 3查看 16.5K关注 0票数 5

this question ask again,但我找不到ios 10

代码语言:javascript
运行
复制
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")
 }

快照未呈现的视图会导致空snapshot.Ensure,您的视图在快照之前或屏幕更新后的快照中至少呈现过一次。

当我旋转相机,拍摄一个比这个错误发生。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-10-17 06:51:27

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

代码语言:javascript
运行
复制
DispatchQueue.global(qos: .userInitiated).async
{
     self.present(self.imagePicker, animated: true, completion: nil)

}
票数 6
EN

Stack Overflow用户

发布于 2017-02-01 01:59:42

我得到了错误

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

相反,使用DispatchQueue.main.async对我来说是有效的。

票数 6
EN

Stack Overflow用户

发布于 2017-03-23 18:12:07

此行为不限于UIImagePickerController。下面是一个UIViewController的示例,它以模式方式显示另一个UIViewController。在第二个UIViewController中,Safari被启动以显示一个URL,从而触发相同的错误消息,即“不能使用afterScreenUpdates:NO快照视图(>),因为视图不在窗口中。请使用afterScreenUpdates:YES”。

我还没有找到任何方法来压制这条消息,但在我的应用程序中,它并没有坏处。我认为这里发生的事情是,一些苹果代码正在对应用程序的视图层次结构进行快照,但是在快照拍摄之前,键盘(由一个单独的UIWIndow拥有)还没有呈现。

代码语言:javascript
运行
复制
/* 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) })
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40043786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档