我在我的场景/视图中设置了一个UIButton,按钮显示了ViewController调用场景的时间。问题是当我点击Button并调用我的GameScene时,Button仍然存在。我想我以错误的方式设置了按钮
我想问题是,我无法在startGame
函数中的button1上调用import Foundation
import SpriteKit
import UIKit
class MenuScene: SKScene {
override init(size: CGSize) {
super.init(size: size)
backgroundColor = SKColor.grayColor()
let label = SKLabelNode(fontNamed: "CourierNewPS-BoldMT")
label.text = "Start Game"
label.fontSize = 40
label.fontColor = SKColor.blackColor()
label.position = CGPoint(x: size.width/2, y: size.height/2)
addChild(label)
}
override func didMoveToView(view: SKView) {
let button1=UIButton(frame: CGRectMake(size.width/2, size.height/2, 300, 100))
button1.backgroundColor = UIColor.greenColor()
button1.setTitleColor(UIColor.blackColor(), forState: .Normal)
button1.setTitle("Unfocused", forState: .Normal)
button1.setTitle("Start", forState: .Focused)
button1.addTarget(self, action: "startGame:", forControlEvents: UIControlEvents.PrimaryActionTriggered)
self.view?.addSubview(button1)
}
func startGame(sender:UIButton) {
let gameView = view! as SKView
gameView.ignoresSiblingOrder = true
let reveal = SKTransition.flipHorizontalWithDuration(0.2)
let scene = GameScene(size: self.size)
gameView.presentScene(scene, transition:reveal)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
函数。
我该如何解决这个问题?任何帮助表示赞赏!
#include <stdio.h>
int main()
{
int N, a, divide, flag=0;
printf("Please enter a positive integer ");
scanf("%d",&N);
if (N<2||N>1000000)
{
printf("Error!");
return 0;
}
for(a=2;a<=N/2;++a)
{
if(N%a==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("The number %d is a prime number.", N);
else
{
printf("The number %d is not a prime number.\nThe prime factors of %d are:",N, N);
divide = 2;
while(N!=0&&flag==1){
if(N%divide!=0)
divide = divide + 1;
else {
N = N / divide;
printf("%d",divide);
if(N==1)
break;
}
}
}
return 0;
}
答案 0 :(得分:1)
您可以使用<String, Void, String>
方法button1
访问sender
个对象。在这种情况下,它是startGame(sender:UIButton)
的引用。你可以从中调用button1
方法:
removeFromSuperview