我试图以编程方式将一个包含nib文件的视图放置在navigationcontroller下。用户交互时,视图应展开。我在此处使用YNDropDownMenu将视图放置在嵌入式导航控制器下,当用户单击该视图时,该视图将展开。它是一个nibfile,已添加到视图并添加到页面。工作时看起来像这样:
以编程方式添加约束时,我得到了:
我正在使用这些约束将视图放置在导航控制器下:
// Add Filter Menu
let ZBdropDownViews = Bundle.main.loadNibNamed("DropDownViews", owner: nil, options: nil) as? [UIView]
let FFA409 = UIColor.init(red: 239/255, green: 239/255, blue: 244/255, alpha: 1.0)
if let _pokeDownViews = PokeDownViews {
// Inherit YNDropDownView if you want to hideMenu in your dropDownViews
let view = YNDropDownMenu(frame: CGRect(x: 0, y: (navigationController?.navigationBar.frame.height)! + 20, width: (navigationController?.navigationBar.frame.width)! + 15, height: 45), dropDownViews: _pokedropDownViews, dropDownViewTitles: ["Sort By"])
view.setImageWhens(normal: [UIImage(named: "Search"),UIImage(named: "Leaf Icon"),UIImage(named: "Leaf Icon"),UIImage(named: "Leaf Icon")], selectedTintColorRGB: "FFA409", disabledTintColorRGB: "D3D3D3")
view.setLabelColorWhen(normal: .purple, selected: FFA409, disabled: .purple)
view.setLabelColorWhen(normalRGB: "000000", selectedRGB: "FFA409", disabledRGB: "D3D3D3")
view.setLabelFontWhen(normal: .systemFont(ofSize: 12), selected: .boldSystemFont(ofSize: 16), disabled: .systemFont(ofSize: 16))
// view.setLabel(font: .systemFont(ofSize: 12))
view.backgroundBlurEnabled = true
// view.bottomLine.backgroundColor = UIColor.black
view.bottomLine.isHidden = false
// Add custom blurEffectView
self.view.addSubview(view)
self.edgesForExtendedLayout = []//Optional our as per your view ladder
view.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
let guide = self.view.safeAreaLayoutGuide
view.trailingAnchor.constraint(equalTo: guide.trailingAnchor).isActive = true
view.leadingAnchor.constraint(equalTo: guide.leadingAnchor).isActive = true
view.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true
view.heightAnchor.constraint(equalToConstant: 50).isActive = true
} else {
NSLayoutConstraint(item: view,
attribute: .top,
relatedBy: .equal,
toItem: view, attribute: .top,
multiplier: 1.0, constant: 0).isActive = true
NSLayoutConstraint(item: view,
attribute: .leading,
relatedBy: .equal, toItem: view,
attribute: .leading,
multiplier: 1.0,
constant: 0).isActive = true
NSLayoutConstraint(item: view, attribute: .trailing,
relatedBy: .equal,
toItem: view,
attribute: .trailing,
multiplier: 1.0,
constant: 0).isActive = true
view.heightAnchor.constraint(equalToConstant: 50).isActive = true
}
let backgroundView = UIView()
backgroundView.backgroundColor = .black
view.blurEffectView = backgroundView
view.blurEffectViewAlpha = 0.85
// Open and Hide Menu
// view.alwaysSelected(at: 0)
// view.disabledMenuAt(index: 2)
//view.showAndHideMenuAt(index: 3)
view.setBackgroundColor(color: UIColor.groupTableViewBackground)
backgroundView.layer.borderWidth = UIScreen.main.bounds.width
// view.layer.borderWidth = UIScreen.main.bounds.width
view.layer.cornerRadius = 7
PokedropDownViews?.forEach({ (dropDownView) in
if dropDownView.isKind(of: PokeFilterMemeView.self) {
(dropDownView as? PokeFilterMemeView)?.menuViewDelegate = self
}
})
单击时,视图应展开,以便用户可以看到视图中包含的所有项目,但是,我似乎无法扩展视图。
我不确定该如何解决。有人可以帮我吗?
谢谢。