gpt4 book ai didi

ios - 为什么按钮不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 07:34:19 25 4
gpt4 key购买 nike

“开始按钮”没有正常工作。单击时应隐藏 subview 。这是 View Controller 。我尝试将最终函数放在不同的地方。

class timeViewController: UIViewController {


var score = 0
var buttonState: Int = 0;
var gameOver = UIView()

@IBAction func start(sender: AnyObject) {

if(displayTime.text != stoptimer.text){

var gameOver = UIView(frame: CGRectMake(0, 0, 0, 0))
gameOver.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.2)
//gameOver.opaque = false
self.view.addSubview(gameOver)
UIView.animateWithDuration(0, animations:{
gameOver.frame.size = CGSizeMake(667, 667)
})

let gobutton = UIButton()
let image = "button.png"
gobutton.setImage(UIImage(named: image), forState: .Normal)
gobutton.frame = CGRectMake(135, 300, 95, 95)
gobutton.addTarget(self, action: "pressed:" , forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(gobutton)

func pressed(sender: UIButton!){
gameOver.removeFromSuperview()
}
}
}

最佳答案

要删除您对此代码的“GaneOver” View 更改:

gameOver.removeFromSuperview()

我希望你在 viewDidLoad 或 viewWillAppear 之外编写“func pressed”

关于ios - 为什么按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30906831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com