Ios 如何使下拉单元格与uiview重叠
我有一个自定义按钮设置,它更像是用UIButton包装uiview,当我触摸它时会显示一个名称列表。问题是在我的视图控制器中,当我尝试点击按钮时,自定义按钮下有一个uiview。我的名单在uiview后面。如何制作列表在uiview上这是我的UI和代码设置 请看,有一个hello和world的列表,但是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
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)
作为旁注,有几点提示:
- 试着从简单的元素开始
- 使用普通的
object(给它们不同的背景色),这样您就可以处理更少的代码李>UIView
- 完成基本任务后,添加“自定义”元素
- 使用普通的
- 在这里询问StackOverflow的问题时
- 尽量包含足够的代码,以便有人可以复制/粘贴并运行它来帮助了解发生了什么。例如,没有人知道您的
、GView
和HeaderView
对象是什么李>GDropdownSchedule
- 尽量避免使用
扩展。要水平滚动所有参数(其中一行有308个字符长)以了解设置了哪些约束是相当困难的.anchor()
- 尽量包含足够的代码,以便有人可以复制/粘贴并运行它来帮助了解发生了什么。例如,没有人知道您的