如何使下拉单元格重叠uiview

how to make dropdown cell overlapping uiview

我有一个以编程方式设置的自定义按钮设置更像是用 UIButton 包装 uiview,当我触摸它时显示名称列表。问题出在我的视图控制器中,在自定义按钮下有一个 uiview,当我尝试点击该按钮时。我的列表在 uiview 后面。我怎样才能使列表超过 uiview 这是我的 UI 和我的代码设置。

看到有hello和world的列表,但是world被uiview覆盖了

这是我的代码设置

    class AddScheduleViewController: UIViewController {

    let containerTitle      = GView(bgColor: .white, radius: 0)
    let headerView          = HeaderView()

    let scrollView: UIScrollView = {
        let scrollView = UIScrollView()
        scrollView.backgroundColor = .white
        scrollView.translatesAutoresizingMaskIntoConstraints = false
        return scrollView
    }()

    var chooseScheduleDropDown = GDropdownSchedule(type: .system)
}

    override func viewDidLoad() {
        super.viewDidLoad()

        chooseScheduleDropDown = GDropdownSchedule.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
        chooseScheduleDropDown.dropView.options = ["Hello", "World"]
        configure()
    }

    private func configure() {
        view.addSubview(containerTitle)
        containerTitle.layer.cornerRadius = 10
        containerTitle.clipsToBounds = true
        containerTitle.anchor(top: view.safeAreaLayoutGuide.topAnchor, trailing: view.safeAreaLayoutGuide.trailingAnchor, bottom: view.safeAreaLayoutGuide.bottomAnchor, leading: view.safeAreaLayoutGuide.leadingAnchor, topPadding: 16, rightPadding: 19, bottomPadding: 16, leftPadding: 19, width: 0, height: 0)

        containerTitle.addSubview(headerView)
        headerView.anchor(top: containerTitle.topAnchor, trailing: containerTitle.trailingAnchor, bottom: nil, leading: containerTitle.leadingAnchor, topPadding: 0, rightPadding: 0, bottomPadding: 0, leftPadding: 0, width: 0, height: 53)

        containerTitle.addSubview(scrollView)
        scrollView.anchor(top: headerView.bottomAnchor, trailing: containerTitle.trailingAnchor, bottom: containerTitle.bottomAnchor, leading: containerTitle.leadingAnchor, topPadding: 8, rightPadding: 8, bottomPadding: 8, leftPadding: 8, width: 0, height: 0)

        [chooseScheduleDropDown, entryView, chooseDateView, chooseClass, startTimeView, endTimeView, descriptionView, saveBtn].forEach {
            v in
            v.translatesAutoresizingMaskIntoConstraints = false
            scrollView.addSubview(v)
        }

    NSLayoutConstraint.activate([

            chooseScheduleDropDown.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
            chooseScheduleDropDown.topAnchor.constraint(equalTo: scrollView.topAnchor),
            chooseScheduleDropDown.widthAnchor.constraint(equalToConstant: 285),
            chooseScheduleDropDown.heightAnchor.constraint(equalToConstant: 60),

            entryView.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor),
            entryView.topAnchor.constraint(equalTo: chooseScheduleDropDown.bottomAnchor, constant: topPadding),
            entryView.widthAnchor.constraint(equalToConstant: 285),
            entryView.heightAnchor.constraint(equalToConstant: 60)
    ])
}

假设您的 "list" 是 UIView 的子类(或 table 视图,随便什么),并且它也被添加为您的 scrollView 的子视图,你可以把它放在其他子视图前面:

scrollView.bringSubviewToFront(entryView)

作为旁注,一些提示:

  • 尝试从简单的元素开始。

    • 使用简单的 UIView 对象(给它们不同的背景颜色),这样您需要处理的代码就更少了。
    • 完成基本任务后,添加 "custom" 元素。
  • 在 Whosebug 上提问时,

    • 尝试包含足够的代码,以便其他人可以 copy/paste 和 运行 它来帮助弄清楚发生了什么。例如,没有人知道您的 GViewHeaderViewGDropdownSchedule 对象是什么。
    • 尽量避免使用 .anchor() 扩展名之类的东西。水平滚动所有参数(其中一行长 308 个字符)以了解正在设置的约束是相当困难的。