尝试在完成处理程序中从故事板呈现模态时的EXC_BREAKPOINT

时间:2017-06-26 21:19:24

标签: scenekit presentmodalviewcontroller ios11 xcode9-beta arkit

在我的ViewController.swift中,我有这个方法,在完成框的动画后以模态方式呈现视图控件:

@objc func sceneTapped(recognizer: UITapGestureRecognizer) {
    let location = recognizer.location(in: sceneView)

    let hitResults = sceneView.hitTest(location, options: nil)

    if hitResults.count > 0 {
        let result = hitResults[0]
        let box = result.node

        let fadeAction = SCNAction.fadeOut(duration: 1.0)
        let rotateAction =  SCNAction.rotate(by: CGFloat(Double.pi*2), around: SCNVector3(x: 0.5, y: 1.5, z: 0), duration: 1.0)
        let groupActions = SCNAction.group([rotateAction, fadeAction])

        if box.name == Present.left.rawValue || box.name == Present.middle.rawValue || box.name == Present.right.rawValue {
            box.runAction(groupActions, completionHandler: presentWebView)
        }

    }

}

presentWebView使用故事板来实例化viewcontroller:

func presentWebView(){
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "webViewController")
        self.present(vc, animated: true, completion: nil)
    }

但每次应用都会self.present(vc, animated: true, completion: nil)EXC_BREAKPOINT (code=1, subcode=0x1a1579b50)

崩溃

但是,当我没有在完成处理程序中呈现视图控制器时,即:

@objc func sceneTapped(recognizer: UITapGestureRecognizer) {
    presentWebView()
}

这完全没问题

所以我不明白为什么在完成处理程序中呈现视图控制器会导致崩溃。

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

主线程中不会调用SCNAction完成处理程序。

根据UIKit指南,您的UI代码需要在主线程上运行。您应该可以使用DispatchQueue.main.async { ... }

执行此操作