ios - 尝试转换场景时无法将 UIView 的值转换为 SCNView

标签 ios swift xcode uiview

嘿,我有 2 个场景,都以相同的方式设置。我现在所处的场景称为“Extra1”,我试图到达的场景称为 GamePlay。使用此代码没有错误,但每次尝试调用应该让我更改 View Controller 的函数时它都会崩溃。两种 View 都转换良好,直到我尝试转换。错误指向此代码:

let scnView = self.view as! SCNView

这是错误: enter image description here

代码:

     import UIKit
     import GLKit
     import GameKit
     import SceneKit
     import StoreKit
     import SpriteKit
     import QuartzCore
     import Foundation
     import AVFoundation
     import AudioToolbox
     import GameController

     class Extra1: UIViewController, ADBannerViewDelegate, SKPhysicsContactDelegate,SKSceneDelegate, SCNSceneRendererDelegate, SCNPhysicsContactDelegate {

 override func viewDidLoad() {
    super.viewDidLoad()

    let scnView = self.view as! SCNView

    //scnView.delegate = self
    scnView.scene = FieldScene
    scnView.playing = true
    scnView.loops = true
    self.view.multipleTouchEnabled = true
    scnView.multipleTouchEnabled = true
    self.HUDView = GameScene(size: scnView.bounds.size)
    self.HUDView.delegate = self
    scnView.overlaySKScene = self.HUDView
    scnView.delegate = self
    scnView.overlaySKScene!.delegate = self
    scnView.overlaySKScene!.userInteractionEnabled = true
    scnView.backgroundColor = UIColor.clearColor()
    scnView.showsStatistics = false

    // Error happens when this function is called. If function isnt called the view call justs fine
      func MoveControls() {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("GamePlay")
    self.presentViewController(vc, animated: true, completion:nil)


}

更新以下答案: enter image description here

最佳答案

我认为崩溃线位于 GamePlay 场景内。 如果是,请打开 Storyboard并将GamePlayViewControllerview类更改为SCNView

关于ios - 尝试转换场景时无法将 UIView 的值转换为 SCNView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39338200/

相关文章:

ios - 不会在 iPad 上的 LinkedIn App 中触发身份验证窗口

ios - KeyboardWillShow 中设置的执行顺序错误

objective-c - Objective-C : How do I add custom table view cells to a subview of a UIViewController

ios - 更改单个单元格 UITableView 的高度

ios - 访问 NSManagedObject 数据

ios - 如何在 xcode 中同时调试两个应用程序?

ios - 比较uipickerdate和当前日期

ios - iOS 9 中的 POST 值获取错误(NSURLSession/NSURLConnection HTTP 加载失败(kCFStreamErrorDomainSSL,-9813)

objective-c - 2x 图像不适用于 Retina 设备

objective-c - CVMetalTextureGetTexture 所有权?