为什么我不能在模拟器中点击uibutton但可以在我的硬件iPhone上使用?

问题描述 投票:0回答:2

我的视图控制器顶部有两个按钮,以模态显示。奇怪的是,当我在模拟器中单击按钮时,这些按钮根本无法选择。当我在iPhone上使用这些按钮时,它们不会造成任何问题。

btn.addTarget(self, action: #selector(sendTapped), for: .touchUpInside)

这就是我将功能添加到按钮的方式

整个按钮代码:

let post: UIButton = {
        let btn = UIButton()

        btn.frame = CGRect(x: 0, y: 0, width: 60, height: 30)
        btn.setTitleColor(UIColor.lightGray.adjust(by: 20), for: .normal)
        btn.isEnabled = false
        btn.setTitle("Post", for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 20, weight: .bold)
        btn.addTarget(self, action: #selector(sendTapped), for: .touchUpInside)

        return btn
    }()

enter image description here

ios uikit ios-simulator
2个回答
0
投票

0
投票

    视图控制器会覆盖不调用超级方法的touchesBegan(_:with :)方法。
  • UIView userInteractionEnabled通过InterfaceBuilder或以编程方式在该按钮上设置为false

  • 按钮在将userInteractionEnabled设置为false的视图下面

© www.soinside.com 2019 - 2024. All rights reserved.