简体   繁体   English

在Swift中将视图添加到SpriteKit场景

[英]Adding a view to a SpriteKit scene in Swift

I'm trying to add an iAd banner to a SpriteKit scene, but I found out that I can't do that without adding a view/subview to the SpriteKit scene. 我正在尝试将iAd横幅添加到SpriteKit场景,但是我发现,如果不向SpriteKit场景添加视图/子视图,就无法做到这一点。 How can I do this? 我怎样才能做到这一点?

您需要访问SKScene的view

self.view?.addSubview(yourSubview)

SKScene provides didMoveToView , which in turn provides the current SKView on which you can use addSubview , since it inherits from UIView . SKScene提供didMoveToView ,后者又提供了当前的SKView ,您可以在其上使用addSubview ,因为它继承自UIView

Another option is to directly access the view of the scene and call addSubview : 另一个选择是直接访问场景视图并调用addSubview

self.view?.addSubview(subview)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM