【问题标题】:Tab bar - adding a new beam to all controllers选项卡栏 - 向所有控制器添加新光束
【发布时间】:2018-03-31 14:11:51
【问题描述】:

Example

有没有人做过这样的例子? 我希望它在其他控制器之间传递时一直显示。我不想在每个控制器中再次创建它。

【问题讨论】:

  • 新光束是什么意思?
  • 只需将包含您想要显示的任何内容的视图添加到其他所有内容之上。
  • 我希望它在其他控制器之间传递时一直显示。我不想在每个控制器中再次创建它。
  • 然后将其添加到 tabbarcontroller 的视图中。
  • 我该怎么做呢?我无法在“TabBarController”中添加

标签: ios swift xcode swift3 uitabbarcontroller


【解决方案1】:

覆盖 TabBar 控制器的视图确实加载,以创建您的 beamView:

let beamViewHeight:CGFloat = 60

let beamView = UIView()
beamView.translatesAutoresizingMaskIntoConstraints = false
beamView.backgroundColor = .black
self.view.addSubview(beamView)

添加约束使其底部对齐,标签栏顶部:

let bottom = NSLayoutConstraint(item: beamView, attribute: .bottom, relatedBy: .equal, toItem: self.tabBar, attribute: .top, multiplier: 1, constant: 0)
let leading = NSLayoutConstraint(item: beamView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0)
let trailing = NSLayoutConstraint(item: beamView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0)
let height = NSLayoutConstraint(item: beamView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: beamViewHeight)

view.addConstraints([bottom, leading, trailing, height])

看起来像这样:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-24
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 2014-12-02
    相关资源
    最近更新 更多