【问题标题】:Moving Tab Bar to the top of the screen swift将标签栏快速移动到屏幕顶部
【发布时间】:2016-12-23 11:06:07
【问题描述】:

我希望标签栏位于屏幕顶部。一篇文章建议执行以下操作(我将以下代码放在 UITabBarController 的 viewDidLoad() 中):

代码

let tabBar = self.tabBar

// yStatusBar indicates the height of the status bar
let yStatusBar = UIApplication.sharedApplication().statusBarFrame.size.height

// Set the size and the position in the screen of the tab bar
tabBar.frame = CGRectMake(0, yStatusBar, tabBar.frame.size.width, tabBar.frame.size.height)

这个解决方案有两个问题:

  1. 屏幕底部留下一个黑色区域,标签栏所在的位置

  2. 标签栏覆盖屏幕顶部的视图 - 该视图的约束是相对于设备的,但它们应该是相对于标签栏的。但是,当在 IB 中设计屏幕时,没有可关联的 Tab 栏。

有没有办法克服这些问题?附言我是IOS新手

【问题讨论】:

  • 这违反了人机界面指南,可能不是一个好主意。如果你还在,请看答案:stackoverflow.com/questions/29579992/…
  • 我的应用程序是为 Android 编写的,现在我正在将它移植到 iPhone。在 Android 中,这是大多数应用程序的工作方式。

标签: ios swift tabbar


【解决方案1】:

虽然它违反了人机界面指南,但如果你真的想这样做,还是存在黑客攻击的。

您可以在情节提要中创建一个空白 UIView(设置了适当的约束),它本质上是加载时 tabBar 的占位符。

然后,您为其他视图设置相对于您已设置的视图的顶部约束。

这可行,但可能不是这样做的最佳做法

【讨论】:

    【解决方案2】:
    let tabBar = self.tabBarController?.tabBar
    // Set the size and the position in the screen of the tab bar
    tabBar?.frame = CGRect(x: 0, y: self.view.frame.height, width: (tabBar?.frame.size.width)!, height:  (tabBar?.frame.size.height)!)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 1970-01-01
      相关资源
      最近更新 更多