gpt4 book ai didi

ios - 调整 Navigation Controller 下的 MenuBar

转载 作者:可可西里 更新时间:2023-11-01 01:57:04 25 4
gpt4 key购买 nike

enter image description here

当我尝试在不同的设备上运行时,Iphone 8 上的菜单栏似乎低于 Iphone X,我该如何针对每个屏幕以编程方式调整它们?这是我的菜单栏代码

customCollectionView = MenuBar(frame: CGRect(x: 0, y:(navigationController?.navigationBar.frame.height)!, width: view.frame.width, height: 50))
customCollectionView.translatesAutoresizingMaskIntoConstraints = true
customCollectionView.collectionView.isScrollEnabled = false
customCollectionView.collectionView.delegate = self
view.addSubview(customCollectionView)
menubarViewConstraints()

menuBar 约束函数

func menubarViewConstraints(){
customCollectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
customCollectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
customCollectionView.topAnchor.constraint(equalTo: (navigationController?.navigationBar.bottomAnchor)!).isActive = true
}

将纵向模式切换为横向模式:

enter image description here

最佳答案

这里的问题是 iPhone X 上的安全区域(任何 future 可能的 iOS 设备)。

如果您将 init 框架调用的 y 位置更改为以下它应该可以工作。

y:((navigationController?.navigationBar.frame.height)!) + (navigationController?.navigationBar.frame.origin.y) + 30

基本上这将获取导航栏的高度并添加 Y 原点位置,最后添加 30。

使用设备安全区域可能有更好的方法来实现此目的,但这是第一个想到的方法,似乎可行。

关于ios - 调整 Navigation Controller 下的 MenuBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51623533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com