使用SWiFT SpriteKit我想删除' createLeftButtonFirst'和' createLeftButtonFirst'屏幕上的按钮当按下“按下第一个”按钮时和' buttonPressedRightFirst'被压了。你有机会帮我这个吗?
以下是代码:
func createLeftButton () {
let button = UIButton();
button.frame = CGRectMake(self.frame.width - self.frame.width, 0, self.frame.width / 2, self.frame.height) // X, Y, width, height
button.backgroundColor = UIColor.greenColor()
button.addTarget(self, action: "buttonPressedRight:", forControlEvents: .TouchUpInside)
self.view!.addSubview(button)
button.layer.zPosition = 0
}
func createRightButton () {
let buttonRight = UIButton();
buttonRight.frame = CGRectMake(self.frame.width / 2, 0, self.frame.width / 2, self.frame.height) // X, Y, width, height
buttonRight.backgroundColor = UIColor.blueColor()
buttonRight.addTarget(self, action: "buttonPressedLeft:", forControlEvents: .TouchUpInside)
self.view!.addSubview(buttonRight)
buttonRight.layer.zPosition = 0
}
func createLeftButtonFirst () {
let buttonFirst = UIButton();
buttonFirst.frame = CGRectMake(self.frame.width - self.frame.width, 0, self.frame.width / 2, self.frame.height) // X, Y, width, height
buttonFirst.backgroundColor = UIColor.grayColor()
buttonFirst.addTarget(self, action: "buttonPressedRightFirst:", forControlEvents: .TouchUpInside)
self.view!.addSubview(buttonFirst)
buttonFirst.layer.zPosition = 1
}
func createRightButtonFirst () {
let buttonRightFirst = UIButton();
buttonRightFirst.frame = CGRectMake(self.frame.width / 2, 0, self.frame.width / 2, self.frame.height) // X, Y, width, height
buttonRightFirst.backgroundColor = UIColor.blackColor()
buttonRightFirst.addTarget(self, action: "buttonPressedLeftFirst:", forControlEvents: .TouchUpInside)
self.view!.addSubview(buttonRightFirst)
buttonRightFirst.layer.zPosition = 1
}
func buttonPressedRight(sender: UIButton!) {
if buttonPressed == 0 {
player.physicsBody?.applyImpulse(CGVector(dx: -15, dy: 0))
buttonPressed = 1
}
}
func buttonPressedLeft(sender: UIButton!) {
if buttonPressed == 1 {
player.physicsBody?.applyImpulse(CGVector(dx: 15, dy: 0))
buttonPressed = 0
}
}
/* First Buttons*/
func buttonPressedRightFirst(sender: UIButton!){
player.physicsBody?.applyImpulse(CGVector(dx: -15, dy: 0))
buttonPressed = 1
}
func buttonPressedLeftFirst(sender: UIButton!){
player.physicsBody?.applyImpulse(CGVector(dx: 15, dy: 0))
buttonPressed = 0
self.removeFromParent()
}
答案 0 :(得分:0)
也许有人会在寻找与我相似的答案,所以我正在发布简单的解决方案-要删除点击的按钮,您应该调用函数:
union
此行应放置在按钮操作目标中:
<div *ngIf= isIdleState" >
<div class="modal-dialog modal-sm" style="display:block;">
<div class="modal-content">
<div class="modal-header">
<h4>Session Timeout warning</h4>
</div>
<div class="modal-body">
you will be timed out in {{countdown}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="reset()">Continue</button>
</div>
</div>
</div>
答案 1 :(得分:-1)
按下它们时,只需让它们hidden
:
func leftButtonPressed(sender: UIButton!) {
leftButton.hidden = true
rightButton.hidden = true
}
func rightButtonPressed(sender: UIButton!) {
leftButton.hidden = true
rightButton.hidden = true
}