如何使下拉单元重叠uiview

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

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

看到有一个hello和world列表,但是这个世界被uiview覆盖了。

listdropdown

这是我的代码设置

    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)
    ])
}
ios swift uiview autolayout
1个回答
0
投票

[假设您的“列表”是UIView的子类(或表视图,无论如何),它也已添加为scrollView的子视图,您可以使用以下命令将其置于其他子视图的前面:] >

scrollView.bringSubviewToFront(entryView)

作为附注,有几点提示:

  • 尝试从简单元素开始。

    • 使用普通的UIView对象(为它们提供不同的背景颜色),因此您需要处理的代码更少。
    • 完成基本任务后,添加“自定义”元素。
  • 在此处在StackOverflow上提问时,>>

    • [尝试包含足够的代码,以便有人可以复制/粘贴并运行它以帮助确定发生了什么。例如,没人知道您的GViewHeaderViewGDropdownSchedule对象是什么。
    • 尝试避免使用.anchor()扩展名之类的东西。要在所有参数中水平滚动(一行中的行长为308个字符),以了解所设置的约束是相当困难的。
  • © www.soinside.com 2019 - 2024. All rights reserved.