我有一个我已经使用 xib 文件创建的 View 。
现在我想向这个 View 添加一些小元素,这些元素将使用来自 SpriteKit 的一些物理动画,所以现在我需要一个 SKView。
是否可以将 SKView 添加为与我的 xib View 相对应的 View 的 subview ?我试过这个,它似乎没有显示任何东西。
以下是与我的 XIB View 对应的 ViewController:
this.myCustomSKView = new CustomSKView()
this.View.AddSubview( this.myCustomSKView );
我的自定义 SKView 的 ViewController 具有:
public override void ViewWillLayoutSubviews ()
{
base.ViewWillLayoutSubviews ();
if(this.SKView.Scene == null)
{
this.SKView.ShowsFPS = true;
this.SKView.ShowsNodeCount = true;
this.SKView.ShowsDrawCount = true;
var scene = new MyCustomSKScene (this.SKView.Bounds.Size);
this.SKView.PresentScene (scene);
}
}
最佳答案
我只是尝试了一下,并且成功了。
这是我所做的唯一改变
-(void)viewDidLoad {
[super viewDidLoad];
// Next line is all I changed...
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
我添加了一些其他的 UIKit 来展示它是如何在一个 View 中显示它的一个小 SK 游戏。
不确定这是否是最好的方法,但我希望我能回答你的问题。
我同意 Lionserdar,您应该查看 UIKit Dynamics。
关于ios7 - 将 SpriteKit View 集成到 xib View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19258567/