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")
}
快照未呈现的视图会导致空snapshot.Ensure,您的视图在快照之前或屏幕更新后的快照中至少呈现过一次。
当我旋转相机,拍摄一个比这个错误发生。
发布于 2016-10-17 06:51:27
自我解决方案像魅力一样为我工作:-)希望它对所有人都有帮助
DispatchQueue.global(qos: .userInitiated).async
{
self.present(self.imagePicker, animated: true, completion: nil)
}
发布于 2017-02-01 01:59:42
我得到了错误
此应用程序正在从后台线程修改自动收费引擎,这可能导致引擎损坏和怪异崩溃.
相反,使用DispatchQueue.main.async
对我来说是有效的。
发布于 2017-03-23 18:12:07
此行为不限于UIImagePickerController。下面是一个UIViewController的示例,它以模式方式显示另一个UIViewController。在第二个UIViewController中,Safari被启动以显示一个URL,从而触发相同的错误消息,即“不能使用afterScreenUpdates:NO快照视图(>),因为视图不在窗口中。请使用afterScreenUpdates:YES”。
我还没有找到任何方法来压制这条消息,但在我的应用程序中,它并没有坏处。我认为这里发生的事情是,一些苹果代码正在对应用程序的视图层次结构进行快照,但是在快照拍摄之前,键盘(由一个单独的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) })
}
}
https://stackoverflow.com/questions/40043786
复制相似问题