Ios 如何使下拉单元格与uiview重叠

Ios 如何使下拉单元格与uiview重叠,ios,swift,uiview,autolayout,Ios,Swift,Uiview,Autolayout,我有一个自定义按钮设置,它更像是用UIButton包装uiview,当我触摸它时会显示一个名称列表。问题是在我的视图控制器中,当我尝试点击按钮时,自定义按钮下有一个uiview。我的名单在uiview后面。如何制作列表在uiview上这是我的UI和代码设置 请看,有一个hello和world的列表,但是uiview覆盖了整个世界 这是我的代码设置 class AddScheduleViewController: UIViewController { let container

我有一个自定义按钮设置,它更像是用UIButton包装uiview,当我触摸它时会显示一个名称列表。问题是在我的视图控制器中,当我尝试点击按钮时,自定义按钮下有一个uiview。我的名单在uiview后面。如何制作列表在uiview上这是我的UI和代码设置

请看,有一个hello和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)
    ])
}
假设您的“列表”是
UIView
的子类(或表视图,无论什么),并且它也被添加为
scrollView
的子视图,您可以将它放在其他子视图之前,并使用:

scrollView.bringSubviewToFront(entryView)
作为旁注,有几点提示:

  • 试着从简单的元素开始

    • 使用普通的
      UIView
      object(给它们不同的背景色),这样您就可以处理更少的代码
    • 完成基本任务后,添加“自定义”元素
  • 在这里询问StackOverflow的问题时

    • 尽量包含足够的代码,以便有人可以复制/粘贴并运行它来帮助了解发生了什么。例如,没有人知道您的
      GView
      HeaderView
      GDropdownSchedule
      对象是什么
    • 尽量避免使用
      .anchor()
      扩展。要水平滚动所有参数(其中一行有308个字符长)以了解设置了哪些约束是相当困难的

嘿@DonMag你是个活生生的储蓄者,我希望有你这样的导师。谢谢你的留言,也谢谢你的询问。我想添加我的GDropdownSchedule代码,因为它是一条长线。我知道堆栈溢出会抱怨代码太多。这就是为什么我不能添加muchI不明白当我尝试点击我的tableview时,第二个单元格没有响应点击。只有我能点击的第一个手机。我尝试使用您的方法并使用layer.zPosition和UIApplication.shared.keyWindow.bringSubviewsToFront仍然不想点击第二个单元格“尝试点击我的tableview,第二个单元格没有响应”。。。很难说没有更多细节。你的桌面视图是什么?您正在显示的子视图是否部分位于其他视图后面?如果您将tableview单独放在一个视图中,而不放在另一个视图中,它是否正常工作?也许可以试着把一个你可以发布到GitHub或者压缩并共享的文件放在一起。