我试图以编程方式从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 !!
答案 0 :(得分:0)
//set custom class to SCNView