gpt4 book ai didi

UISearchBar 与 iOS 中的状态栏重叠

转载 作者:行者123 更新时间:2023-12-03 13:20:58 25 4
gpt4 key购买 nike

我(就像这里的其他人一样)遇到了和其他人一样的状态栏重叠问题,有点扭曲,这就是为什么我提出一个关于这个的新问题。

似乎有一些机制可以让 UISearchBar 知道它自己的位置,即 总计走出低谷,重新振作起来,重整旗鼓。

jaredsinclair 在这里回答 (iOS 7 status bar back to iOS 6 default style in iPhone app?) ,详细解释了 Apple 工程师如何允许我们将逻辑引入我们的应用程序,以便尽可能地融入用户的环境。

我仔细检查了我的应用程序中的每个 UIViewController 并进行了最轻微的修改。

在大多数情况下,我能够使用下面的代码解决问题,我在几个 SO 答案中找到了这些代码

// Do any additional setup after loading the view.
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]){
self.edgesForExtendedLayout = UIRectEdgeNone;
}

然而,无论我在 UINavigationBar 隐藏的特定 View 中做什么,这都不起作用。

UISearchBar on top of status bar

基于在 SO 中找到的解决方案,我能够通过将以下逻辑添加到这个特定的 UIViewController 来解决这个问题
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
viewFrame.origin.y = viewFrame.origin.y+statusBarFrame.size.height;
}

这会根据状态栏的高度将 UIViewController n 像素向下推。

这里显示的效果

Hacked position UISearchBar

问题是当我进入搜索字段时,UISearchBar 会在顶部自己添加一个 20px 的填充,这会抵消整个 UI。

enter image description here

这使我得出这样的结论,即 UISearchBar 会尝试自行调整,巧合的是,它会自行调整与状态栏高度完全相同的量。

如果我不修改位置,一旦我进入搜索字段,这个自动调整就会将 UISearchBar 整齐地对齐在状态栏下方。

我希望我已经详细说明了我的困惑,我想知道是否有人对解决方案有任何想法。

最佳答案

如果 navigationBar 可见,请在 ViewDidLoad 中执行以下操作:

self.edgesForExtendedLayout = UIRectEdgeNone;

如果 navigationBar 被隐藏,请在 ViewDidLoad 中执行以下操作:

通过将所有 UIView 元素移动 20pt 来调整它们

关于UISearchBar 与 iOS 中的状态栏重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18975920/

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