从SKScene访问UIView

时间:2017-01-28 01:57:00

标签: swift

我有一个UIView

@IBOutlet weak var whiteBox: UIView!

在我的UIViewController类中。有没有办法从我的SKScene课程访问它?

1 个答案:

答案 0 :(得分:0)

SKScene添加这些初始值设定项(假设您的UIViewController被称为GameViewController

var viewController: GameViewController
init(size: CGSize, parent: GameViewController) {
    self.viewController = parent
    super.init(size: size)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

GameViewController中用此替换当前的GameScene初始值设定项(假设您的SKScene被称为GameScene

let scene = GameScene(size: (self.view?.bounds.size)!, parent: self)

要访问UIView,请使用此代码:

viewController.whiteBox

希望这有帮助!