des*_*ume 66 statusbar uisearchbar uisearchdisplaycontroller ios ios7
我正在为iOS 7更新我的应用程序,并且我正在调整所有视图以考虑新的透明状态栏(我的应用程序仍将使用不透明的导航栏).
在每个视图中调整状态栏相对容易,除了我在一个视图控制器中连接到UISearchDisplayController的UISearchBar时遇到的一个主要问题.
搜索栏似乎正常显示,如下所示:
搜索栏http://imageshack.us/a/img163/9128/06vx.png
问题是,一旦我开始搜索,导航栏就会消失(应该如此),但其他一切也会向上移动以重叠状态栏:
破碎的搜索栏http://imageshack.us/a/img11/8237/corh.png
这似乎没有按预期工作,因为屏幕变暗发生在搜索栏下方20个像素处,搜索栏应该在此处结束.
在iOS 7中是否有针对此的内置解决方案?每次用户开始和结束搜索时,我不必为每个视图手动调整帧.
谢谢!
Ded*_*oel 88
将以下行放在viewDidLoad中为我修复它:
self.edgesForExtendedLayout = UIRectEdgeNone;
Run Code Online (Sandbox Code Playgroud)
des*_*ume 21
感谢您带领我走上正轨!您的解决方案有效,除了它只移动了搜索栏的框架,使我的其他子视图处于错误的位置.我唯一改变的是在视图中移动所有子视图,并为其制作动画.
谢谢!
-(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;
}];
}
}
Run Code Online (Sandbox Code Playgroud)
小智 13
您可能没有使用半透明导航栏?如果是这样,这将解决它.
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
self.navigationController.navigationBar.translucent = YES;
}
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
self.navigationController.navigationBar.translucent = NO;
}
Run Code Online (Sandbox Code Playgroud)
只需将以下代码放入- (void)ViewDidLoad即可.它适用于iOS 7及更高版本
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Run Code Online (Sandbox Code Playgroud)
更新:
if(SYSTEM_VERSION_GREATER_THAN(@"6.1")) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Run Code Online (Sandbox Code Playgroud)
这似乎描述了我遇到的问题; 希望它会帮助我以前的位置.
将已添加到UIViewController/UITablewViewController的SearchDisplayController子类化,
在其实现中添加以下内容:
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
[super setActive:visible animated:animated];
[self.searchContentsController.navigationController setNavigationBarHidden: NO animated: NO];
CGRect frame = self.searchResultsTableView.frame;
frame.origin.y = CGRectGetHeight(self.searchContentsController.navigationController.navigationBar.frame);
frame.size.height = CGRectGetHeight(frame) - CGRectGetMinY(frame);
self.searchResultsTableView.frame = frame;
frame = self.searchBar.frame;
self.searchBar.frame = frame;
[self.searchContentsController.view insertSubview:self.searchBar aboveSubview:self.searchResultsTableView];
}
Run Code Online (Sandbox Code Playgroud)我在下面的代码中解决了这个问题.
- (void) viewDidLayoutSubviews
{
if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
CGRect viewBounds = self.view.bounds;
CGFloat topBarOffset = self.topLayoutGuide.length;
viewBounds.origin.y = topBarOffset * -1;
self.view.bounds = viewBounds;
}
}
Run Code Online (Sandbox Code Playgroud)
我想也许将它添加到viewDidLoad会有所帮助:
if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46620 次 |
| 最近记录: |