我的按钮不起作用,我不知道为什么

伊沃

我正在尝试制作一个真实或大胆的游戏作为我的第一个项目,我没有出错,但按钮不起作用我一步一步地运行代码,当我按下按钮时,它们不起作用 truthsEng 和 DaresEng 是他们在共享源文件夹中的真理和勇气。

import PlaygroundSupport
import UIKit
let view = UIView()
//adding the baground image
let Game = UIImageView(frame: UIScreen.main.bounds)
Game.image = UIImage(named:"Photo.png")
Game.contentMode = .scaleAspectFill
view.insertSubview(Game, at:0)
let lbl = UILabel(frame: CGRect(x:100 , y:100, width: 300, height: 500))
lbl.text = "test"
lbl.textColor = #colorLiteral(red: 0.6313725709915161, green: 0.6470588445663452, blue: 0.9058823585510254, alpha: 1.0)
Game.addSubview(lbl)
let truthButton = UIButton(frame: CGRect(x:100, y: 100, width: 100, height: 69))
truthButton.layer.cornerRadius = 10
truthButton.backgroundColor = #colorLiteral(red: 0.6325997710227966, green: 0.6475543975830078, blue: 0.905613362789154, alpha: 1.0)
truthButton.setTitle("truth", for: UIControl.State.normal)
Game.addSubview(truthButton)
let dareButton = UIButton(frame: CGRect(x:300, y: 400, width: 100, height: 69))
dareButton.layer.cornerRadius = 10
dareButton.backgroundColor = #colorLiteral(red: 0.6352941393852234, green: 0.6470588445663452, blue: 0.886274516582489, alpha: 1.0)
dareButton.setTitle("dare", for: UIControl.State.normal)
Game.addSubview(dareButton)

class Responder: NSObject{
    @objc func PrintTruthAndChangeBaground() {
        lbl.text = truthsEng.randomElement()
        
    }
    @objc func PrintDareAndChangeBaground() {
        lbl.text = daresEng.randomElement()
        
    }
    
}
let responser = Responder()
truthButton.addTarget(responser, action: #selector(Responder.PrintTruthAndChangeBaground), for:.touchUpInside)
dareButton.addTarget(responser, action: #selector(Responder.PrintDareAndChangeBaground), for: .touchUpInside)

PlaygroundPage.current.liveView = Game

Hao Liang

UIKit UIImageView isUserInteractionEnabled

一个布尔值,用于确定是否忽略用户事件并将其从事件队列中删除。

声明 var isUserInteractionEnabled: Bool { get set }

讨论 该属性继承自 UIView 父类。此类将此属性的默认值更改为 false。

您需要将此属性设置为 true。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我不知道为什么这些SQL命令不起作用

我不知道为什么这个Java代码不起作用

pygame游戏尝试不起作用,我不知道为什么

我不知道为什么SDK Manager独立版不起作用

除了ValueError在我的代码中不起作用我不知道为什么

Ajax在这种情况下不起作用,我也不知道为什么

我的产卵系统不起作用,我也不知道为什么

我不知道为什么这个static_assert()代码不起作用

我不知道为什么此联系表格不起作用

我的Matlab代码不起作用,但我不知道为什么?

存储过程不起作用,我也不知道为什么

clearInterval()不起作用,我不知道为什么

我不知道为什么这个 FFmpeg 命令在 android 中不起作用?

不知道为什么我的循环功能在这里不起作用

Hibernate Validator 不起作用,但我不知道为什么

我不知道为什么我的 backgroundImage 不起作用

我不知道为什么我的“if”语句不起作用

我的 gridsearchCV 不起作用,我不知道为什么

SKAction.moveBy 不起作用,我不知道为什么

列表理解逻辑不起作用,我不知道为什么

代码不起作用,我不知道为什么。制作刽子手游戏

我是 React 的新手,我不知道为什么这不起作用

我不知道为什么我的 if 语句不起作用

我不知道为什么渲染在反应中不起作用

我的 axios 实例不起作用,我不知道为什么

我的批处理脚本不起作用,我不知道为什么

此功能不起作用,我不知道为什么

不知道为什么我对作业问题的回答不起作用

puppeteer node.js 代码不起作用。我不知道为什么