0

在我ViewController.swift我有這樣的方法,提出了箱子的動畫完成後,模態一個視圖控制器:EXC_BREAKPOINT

@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用故事板實例化視圖 - 控制:

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

SCNAction完成處理程序將不會在主線程中調用。

根據UIKit指導您的UI代碼需要在主線程上運行。你應該可以使用DispatchQueue.main.async { ... }

相關問題