在 UITabBar 顶部查看

2023-12-27

Similar to what the Spotify or Apple Music app does when a song is playing, it places a custom view on top of the UITabBar: enter image description here

我尝试过的解决方案:

  1. UITabBarController in a ViewController with a max-sized Container View, and the custom view on top of the Container View49pt above the Bottom Layout Guide: enter image description here Problem: Any content in ViewControllers embedded in the UITabBarController constrained to the bottom don't show because they're hidden behind the custom layout. I've tried overriding size forChildContentContainer in UITabBarController, tried updating the bottom layout guide, Nothing. I need to resize the frame of container view of the UITabBarController.

  2. 再次尝试#1,但尝试解决隐藏在其后面的内容的问题增加 UITabBar 的大小 https://stackoverflow.com/questions/24397189/changing-the-height-of-uitabbar-in-ios7-8,然后使用每个 TabBarItem 上的 ImageInset https://stackoverflow.com/questions/37457711/resize-all-viewcontroller-frames-in-tabbarcontroller将其关闭,并在 UITabBar 顶部添加我的自定义视图。效果不太好。有时我想隐藏我的自定义视图。

  3. UITabBarController as root, with each children being a ViewController with a Container View + my custom view: enter image description here But now I have multiple instances of my custom view floating around. If I want to change a label on it, have to change it to all views. Or hide, etc.

  4. 覆盖 UITabBarController 的 UITabBar 属性并返回具有 UITabBar + 我的自定义视图的自定义 UITabBar(用 xib 对其进行膨胀)。Problem:可能是所有尝试中最令人沮丧的。如果您使用以下实例覆盖该属性class MyCustomTabBar : UITabBar {},没有标签显示!是的,我设置了代表myCustomTabBar to self.

倾向于#3,但正在寻找更好的解决方案。


如果您继承 UITabBarController 并以编程方式添加视图,这实际上非常容易。使用此技术会自动支持选项卡栏的旋转和大小更改,无论您使用的是哪个版本。

class CustomTabBarController: UITabBarController {
  override func viewDidLoad() {
    super.viewDidLoad()

    //...do some of your custom setup work
    // add a container view above the tabBar
    let containerView = UIView()
    containerView.backgroundColor = .red
    view.addSubview(containerView)
    containerView.translatesAutoresizingMaskIntoConstraints = false
    containerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
    containerView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true

    // anchor your view right above the tabBar
    containerView.bottomAnchor.constraint(equalTo: tabBar.topAnchor).isActive = true

    containerView.heightAnchor.constraint(equalToConstant: 50).isActive = true
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 UITabBar 顶部查看 的相关文章

随机推荐

  • 如何从服务访问当前登录用户的 HKCU 注册表?

    我想在 Windows 服务中检查存储在每个用户的 HKCU 注册表区域中的一些用户首选项 我怎样才能做到这一点 我看到 HKEY USERS 具有已登录到计算机的每个用户的子项 或类似的东西 并且在这些子项中是每个用户的 HKCU 区域
  • D3 分组条形图 - 选择整个组?

    我有一个类似于的分组条形图https bl ocks org mbostock 3887051 https bl ocks org mbostock 3887051我使用鼠标悬停功能来淡化鼠标当前未悬停的栏 function mouseov
  • 为什么角(半径)不能不同?

    我试图
  • 静默 Windows Installer 安装程序,无需自动重新启动

    目前我有一个MSI http en wikipedia org wiki Windows Installer它执行重大升级 并启动为 msiexec exe i installer msi qn REBOOT ReallySuppress
  • Java Sockets - 发送对象并将对象分发给所有连接的客户端

    所以我在这里 有一个 3D 游戏 效果很好 不过 我希望将其做成多人游戏 我对套接字非常陌生 所以我不完全了解如何使用它们 更具体地说 如何将对象从客户端发送到服务器 然后将该对象分发给所有其他客户端 这是我制作的想要发送的对象 publi
  • mingw64 - 文件下载不正确

    我尝试安装 MinGW w64 但在安装过程中我得到了 文件下载不正确 我有 64 位 win10 和我的安装选项 我使用该链接来源锻造 https sourceforge net projects mingw w64 source dir
  • 在 x86 机器上无锁读/写 int

    假设在一个 C 程序中 我有 P 个线程在 32 位机器上运行 并且int MAX 共享 32 位整数 每个线程都可以读 写 MAX 要求 线程读取的值不应被损坏 例如前 16 位和最后 16 位不同步 问题 我需要一个锁来保护读写吗 或者
  • Windows 7 的spyder 中strptime 的Python ImportError

    我一生都无法弄清楚是什么导致了这个非常奇怪的错误 我正在 windows 7 的spyder IDE 中运行 python 2 7 中的脚本 它一度使用 datetime datetime strptime 我可以运行代码一次 看起来很好
  • “类别不存在。”为 MSMQ 队列创建性能计数器

    我正在尝试这样做 using System Diagnostics var queueCounter new PerformanceCounter MSMQ Queue Messages in Queue machinename priva
  • 即使将“verbose”设置为“False”后,Moviepy 仍然打印进度条

    我试图在调用 write videofile 方法时抑制 moviepy 产生的控制台输出 我将冗长的论点作为 False 传递 但无济于事 它仍然输出类似的内容 0 0 1624 00 00
  • Vim 与用户输入的映射

    我想知道 Vim 是否可以创建一个映射 对于正常模式 允许用户在映射执行之前输入 我想为我最常用的 grep 命令创建快捷方式的映射 我希望该命令允许输入我正在搜索的内容 然后在输入时执行 这就是我想要的 nmap F grep user
  • 如何使用 momentjs 管理每月付款的日期?

    大家好 我已经每周和每两周实施一次 但我需要使用 momentjs 每月实施一次 以满足以下特定要求 可能的付款频率是 每周 每月 每月的同一天 例如3月5日 4月5日 5月5日 对于每月频率 如果某个行项目的开始日期在某些月份中不存在 我
  • PHP - 将 数据作为包含加载是愚蠢的吗

    这可能是一个非常愚蠢的问题 但是加载文件中标签之间的数据并通过 PHP include 加载它是愚蠢的吗 这样可以更轻松地进行编辑 谢谢 不 这不会是愚蠢的 重复代码越少越好
  • HTML 链接尾部斜杠[重复]

    这个问题在这里已经有答案了 The w3学校 http www w3schools com html html links asp文档说 如果子文件夹地址末尾没有斜杠 您可能会向服务器生成两个请求 许多服务器会自动在地址中添加尾部斜杠 然后
  • 在设计数据库时,存储多个真/假值的首选方式是什么?

    如标题中所述 在设计数据库时 处理具有多个列的表的首选方法是什么 这些列仅将真 假值存储为单个或值 例如 Y N 或 0 1 同样 不同数据库 例如 Oracle 和 SQL Server 之间是否可能出现一些问题 这些问题可能会影响列的处
  • R中二项式数据的置信区间?

    我知道我需要 Mean 和 s d 来找到间隔 但是 如果问题是 对随机抽取的 1 000 名工人进行的调查显示 其中 520 名是女性 根据调查为女性工人比例创建 95 的置信区间 我如何找到平均值和标准差 您还可以使用prop test
  • Spring MVC 控制器方法什么时候应该有@ResponseBody?

    我用 ResponseBody使用我的 Spring 控制器进行注释 但我不确定何时使用它 另外 我将我的方法命名为index我想知道这是否重要 我的方法头是 RequestMapping value addproduct method R
  • Ansible 中根据特定值对 dict 进行排序

    我在 Ansible 中将以下字典设置为变量 my users name1 value some value1 id 99 type some type1 name2 value some value2 id 55 type some ty
  • WPF 窗口未关闭

    您能告诉初学者为什么这个小型 WPF 应用程序在 WorkflowTermulated 事件触发后没有按预期关闭吗 使用的工作流程立即终止 使用 WPF 应用程序 Net Framework 3 5 public partial class
  • 在 UITabBar 顶部查看

    Similar to what the Spotify or Apple Music app does when a song is playing it places a custom view on top of the UITabBa