我正在使用带有菜单的Swift创建一个应用程序。
在此菜单上,有一个显示视图的按钮。在这个视图中,有一个按钮。
这是我的观点:
let buyHotModeViewHeight = screenHeight * 0.8
let buyHotModeViewWidth = modesWidth
let buyHotModeView = BuyHotModeView(frame: CGRect(x: screenWidth / 2 - buyHotModeViewWidth / 2, y: screenHeight / 2 - buyHotModeViewHeight / 2, width: buyHotModeViewWidth, height: buyHotModeViewHeight))
view.addSubview(buyHotModeView)
这是视图上的按钮:
// MARK: BUY HOT MODE BUTTON
let buyHotModeButtonWidth = frame.width / 4
let buyHotModeButtonHeight = buyHotModeButtonWidth / 2
let buyHotModeButton = UIButton(frame: CGRect(x: frame.width / 2 - buyHotModeButtonWidth / 2, y: topBackground.frame.height - buyHotModeButtonHeight * 1.5, width: buyHotModeButtonWidth, height: buyHotModeButtonHeight))
buyHotModeButton.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.2)
addSubview(buyHotModeButton)
问题是我无法触摸此按钮,没有任何反应(我删除了addTarget
行以简化代码。