问题描述
我正在为iOS 7更新我的应用程序,并且我正在调整所有视图以考虑新的透明状态栏(我的应用程序仍将使用不透明的导航栏)。
I'm updating my app for iOS 7, and I'm in the process of adjusting all my views to account for the new transparent status bar (my app will still use opaque navigation bars).
在每个视图中调整状态栏相对容易,除了我在一个视图控制器中连接到UISearchDisplayController的UISearchBar时遇到的一个主要问题。
It was relatively easy to adjust for the status bar in every view, except one major problem I'm having with a UISearchBar connected to a UISearchDisplayController in one of my view controllers.
搜索栏似乎正常显示,如下所示:
The search bar seems to display normally, as shown below:
问题是,一旦我开始搜索,导航栏就会消失(应该如此),但其他一切也会向上移动以重叠状态栏:
The problem is, as soon as I begin searching, the navigation bar disappears (as it should), but everything else also moves up to overlap the status bar:
由于t变暗,这似乎没有按预期工作他的屏幕出现在搜索栏下方20个像素处,搜索栏应该在那里结束。
This doesn't appear to be working as intended, since the darkening of the screen happens 20 pixels below the search bar, where the search bar should end.
在iOS 7中是否有内置的解决方案?每次用户开始和结束搜索时,我都不必为每个视图手动调整帧。
Is there a built in solution for this in iOS 7? I'd rather not have to manually adjust the frame for every view each time the user begins and ends searching.
谢谢!
推荐答案
感谢您带领我走上正轨!你的解决方案有效,除了它只移动搜索栏的框架,让我的其他子视图在错误的位置。我改变的唯一方法是在我的视图中移动所有子视图,并为其设置动画。
Thank you hodade for leading me on the right track! Your solution worked, except it only moved the search bar's frame, leaving my other subviews in the wrong spot. The only thing I changed was to move all the subviews in my view, as well as animate it.
谢谢!
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
[UIView animateWithDuration:0.25 animations:^{
for (UIView *subview in self.view.subviews)
subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height);
}];
}
}
-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[UIView animateWithDuration:0.25 animations:^{
for (UIView *subview in self.view.subviews)
subview.transform = CGAffineTransformIdentity;
}];
}
}
这篇关于iOS 7 UISearchDisplayController搜索栏在搜索时重叠状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!