UISearchBar重叠iOS中的状态栏 [英] UISearchBar overlaps status bar in iOS

查看:138
本文介绍了UISearchBar重叠iOS中的状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我(就像其他人一样)遇到了与其他人一样的状态栏重叠问题,稍微扭曲了一下,这就是为什么我打开一个关于此问题的新问题。

I (just like everyone else here) am running into the same Status Bar overlap issue that everyone else is, with a little twist, and that is why I opening a new question about this.

似乎有一些机制让UISearchBar知道在哪里定位它自己,这是完全的重击。

There seems to be some mechanism that lets the UISearchBar know where to position it self, which is totally out of whack.

jaredsinclair在这里回答( iOS 7状态栏在iOS应用程序中恢复到iOS 6默认样式?),详细解释了Apple工程师如何允许我们为我们的应用程序引入逻辑,以便尽可能地融入用户的环境。

jaredsinclair answer here (iOS 7 status bar back to iOS 6 default style in iPhone app?) , explains in great detail how the Apple Engineers allow us to introduce logic to our application in order to blend in as much as possible with the user's environment.

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

I went through the process of carefully examining each UIViewController in my application and making the slightest modification possible.

在大多数情况下,我能够使用下面的代码解决问题,我发现有几个SO答案

In most cases I was able to resolve the problem using the code below which I found accross several SO answers

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

无论我在特定视图中做什么,这都行不通UINavigationBar是隐藏的。

This however would not work no matter what I do in a particular view where the UINavigationBar is hidden.

根据SO中找到的解决方案,我可以通过向这个特定的UIViewController添加以下逻辑来解决这个问题

Based on the solution found across SO I was able to solve this issue by adding the following piece of logic to this particular UIViewController

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    CGRect statusBarFrame =  [[UIApplication sharedApplication] statusBarFrame];
    viewFrame.origin.y = viewFrame.origin.y+statusBarFrame.size.height;
}

这将推动UIViewController n 像素取决于 在状态栏的高度上。

This pushes the UIViewController n pixels down "depending" on the height of the status bar.

这里的效果显示在这里

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

The problem is that when I enter the search field the UISearchBar adds by itself a 20px padding on the top, which offsets the entire UI.

这使我得出UISearchBar试图调整自己的结论,巧合的是,它调整自己与状态栏高度完全相同的数量。

This leads me to the conclusion that the UISearchBar tries to adjust itself, and by coincidence it adjust itself the exact same amount as the status bar's height.

如果我没有破解该位置,一旦我进入搜索字段,则此自动调整对齐UISearchBar整齐地位于状态栏下方。

If I don't hack the position, once I enter the search field then this auto adjustment aligns the UISearchBar neatly underneath the status bar.

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

I hope I have detailed my confusion, I am wondering if anybody has any ideas towards a solution.

推荐答案

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

If the navigationBar is visible do the following in ViewDidLoad :

self.edgesForExtendedLayout = UIRectEdgeNone;

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

If the navigationBar is hidden do the following in ViewDidLoad :

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

这篇关于UISearchBar重叠iOS中的状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆