【问题标题】:Adding a UIButton to a SKScene将 UIButton 添加到 SKScene
【发布时间】:2014-03-06 07:49:20
【问题描述】:

UIButton 添加到SKScene 的最佳方法是什么?

我意识到我可能无法将它添加为场景的子视图,那么有什么替代方法可以在场景顶部有一个可点击的按钮?

【问题讨论】:

标签: ios objective-c uikit sprite-kit skscene


【解决方案1】:

您可以选择以下方式之一:

1 - 子类 SKSpriteNode 充当按钮

2 - 在场景中实现触摸代理并在您的“按钮”节点被触摸时做出响应

link 会告诉你如何实现上述两个。

3 - 使用像 SpriteKit Button 这样的组件,可以在 here 找到。

【讨论】:

  • 我认为#2 是最好的解决方案。谢谢!
【解决方案2】:
 /// create a uibutton in skscene (spritkit)

      UIButton * startButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 60, 20)];
                startButton.backgroundColor = [UIColor redColor];

                [self.view addSubview:startButton];

/// if u want to connect it to a method or function /// 

[startButton addTarget:self action:@selector(StartBtn) forControlEvents:UIControlEventTouchUpInside];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多