无法施放类型的价值' UIView' (0x1102beb40)到' SKView' (0x10f0814c8)

时间:2016-10-23 02:44:13

标签: ios swift uiview sprite-kit

我试图以编程方式从UITableView切换到SKView(不能使用故事板在TableView上放置按钮)。

这是必须切换视图的代码:

ViewController.swift:

    func game() {
    let game = GameViewController()
    present(game, animated: true, completion: nil)

}

GameViewController.swift:

import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.
        let skView = self.view as! SKView

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .aspectFill

        skView.presentScene(scene)
    }
}

override var shouldAutorotate : Bool {
    return true
}

override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
    if UIDevice.current.userInterfaceIdiom == .phone {
        return .allButUpsideDown
    } else {
        return .all
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override var prefersStatusBarHidden : Bool {
    return true
   }
}

它给了我错误:

  

无法投放类型的价值' UIView' (0x1102beb40)到' SKView' (0x10f0814c8)。

我知道这是一个代码问题,但我不知道该解决什么问题。

将课程改为SKVIEW DOESN' T WORK !!

1 个答案:

答案 0 :(得分:0)

我之前遇到过同样的问题。转到故事板并在身份检查器中,将自定义类设置为SCNView

//set custom class to SCNView