我有一个带有嵌入式UISearchDisplayController的UITableViewController。在iOS 7中,搜索框位于状态栏下方。是否可以使用interface builder来偏移tableview,以使搜索栏不被状态栏遮盖,并且仍然使用UITableViewController和UISearchDisplayController设置)?
我有一个带有嵌入式UISearchDisplayController的UITableViewController。在iOS 7中,搜索框位于状态栏下方。是否可以使用interface builder来偏移tableview,以使搜索栏不被状态栏遮盖,并且仍然使用UITableViewController和UISearchDisplayController设置)?
self.edgesForExtendedLayout=UIRectEdgeNone;
应该解决这个问题。
UINavigationController
中,然后在navVC
中,只需取消勾选Shows Navigation Bar
即可。
[self.tableView setContentInset:UIEdgeInsetsMake(self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height, 0, 0, 0)];
如果您需要同时适配两种屏幕方向:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self.tableView setContentInset:UIEdgeInsetsMake(self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height, 0, 0, 0)];
}
self.edgesForExtendedLayout = UIRectEdgeNone;
...
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
if (navigation.hiden) {
[self.tbview setContentOffset:CGPointMake(0, -20)];
[self.tbview setContentInset:UIEdgeInsetsMake(20, 0, 0, 0)];
}
else {
[self.tbview setContentOffset:CGPointMake(0, -20)];
[self.tbview setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
}
我需要调整tableview的contentOffset
和contentInset
。我的tableviewcontroller是由模态segue触发的,已经在storyboard中上游嵌入了一个导航控制器。通过将内容插图调整为状态栏的高度,并将内容偏移调整为搜索栏的高度,可以显示从第一行开始的tableview。当用户下拉tableview时,搜索栏会显示。
self.tableView.contentOffset = CGPointMake(0, 44.0);
self.tableView.contentInset = UIEdgeInsetsMake(20.0, 0.0, 0.0, 0.0);
将以下代码放置在您的视图控制器的viewdidload中。
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
}