-2

我有一个需要在 UIWindow 上显示的弹出窗口。弹出窗口有 3 个按钮。弹出窗口完美地添加到窗口中,但弹出窗口上的按钮不响应触摸。

这是我将弹出窗口添加到窗口的代码:

let windowCount = UIApplication.shared.windows.count
UIApplication.shared.windows[windowCount-1].insertSubview(blurView, at: (UIApplication.shared.windows.last?.subviews.count)!)

弹出代码

func setUpHelpMenu(){

            blurView.addSubview(backView)
            _ = backView.anchorPoints(left: blurView.leftAnchor, bottom: blurView.bottomAnchor, right: blurView.rightAnchor,  leftConstant: 0, bottomConstant: 10, rightConstant: 0, widthConstant: blurView.frame.width, heightConstant: 170/812 * blurView.frame.size.height)

            backView.addSubview(resendCode)
            backView.addSubview(editPhoneNumber)
            backView.addSubview(cancel)

            _ = resendCode.anchorPoints(backView.topAnchor, centerX: backView.centerXAnchor, widthConstant: backView.frame.size.width, heightConstant: backView.frame.size.height / 3)
            _ = editPhoneNumber.anchorPoints(resendCode.bottomAnchor, centerX: backView.centerXAnchor, widthConstant: backView.frame.size.width, heightConstant: backView.frame.size.height / 3)
            _ = cancel.anchorPoints(editPhoneNumber.bottomAnchor, centerX: backView.centerXAnchor, widthConstant: backView.frame.size.width, heightConstant: backView.frame.size.height / 3 - 10)
        }

取消按钮设计代码:

let cancel: UIButton = {
        let button = UIButton()
        button.buttonTitleLabelWith(titleEdgeInsets: .zero, title: String(string: "Cancel") as NSString, lineBreakMode: .byWordWrapping, font: UIFont.systemFont(ofSize: 25/1024 * UIScreen.main.bounds.height), textColor:  UIColor.blue.withAlphaComponent(0.80))
        button.isUserInteractionEnabled = true
        button.backgroundColor = .blue
        button.addTarget(self, action: #selector(tapPopUpButtons), for: .touchUpInside)
        return button
    }()

我已经检查了关于 SO 的其他类似问题,但没有一个对我有用。让我知道我错在哪里。

任何帮助,将不胜感激。

4

1 回答 1

0

嗯,我找到了答案。我将选择器添加到错误位置的按钮。删除了此代码

button.addTarget(self, action: #selector(tapPopUpButtons), for: .touchUpInside)

UIButton关闭并添加到viewDidLoad工作中。

于 2018-06-28T04:25:38.973 回答