我的应用程序有一个以表单形式呈现的表格 View Controller 。
在 tableviewcontoller 的顶部有一个 UView,在那个 UIView 里面有一个导航栏和一个搜索栏。
旧版本的 IOS 一切正常,但在 IOS7 中,当用户点击搜索栏时,一切都搞砸了。
正常:
当用户开始输入时:
搜索结束后:
英寸.h
UITableViewController<UITextFieldDelegate,UISearchDisplayDelegate,UISearchBarDelegate>
@property (nonatomic,weak) IBOutlet UINavigationBar *topBar;
尝试了一些东西但是代码似乎没有改变任何东西,但是当放置断点时它进入委托(delegate)方法
英寸.米
//-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
// if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
// CGRect statusBarFrame = self.topBar.frame;
// [UIView animateWithDuration:0.25 animations:^{
// for (UIView *subview in self.tableView.subviews)
// subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height+50);
// }];
// }
//}
//
//-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
// if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
// [UIView animateWithDuration:0.25 animations:^{
// for (UIView *subview in self.tableView.subviews)
// subview.transform = CGAffineTransformIdentity;
// }];
// }
//}
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect frame = self.searchDisplayController.searchBar.frame;
frame.origin.y += self.topBar.frame.size.height;
self.searchDisplayController.searchBar.frame = frame;
}
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect statusBarFrame = self.topBar.frame;
CGRect frame = self.searchDisplayController.searchBar.frame;
frame.origin.y -= statusBarFrame.size.height;
self.searchDisplayController.searchBar.frame= frame;
}
}
#Additional Info
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//self.searchDisplayController.searchBar.searchBarStyle= UISearchBarStyleProminent;
self.edgesForExtendedLayout = UIRectEdgeNone;
//self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
}
}
根据断点,框架位置和大小是正确的,但它们根本没有改变 self.searchDisplayController.searchBar.frame
我也试过
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[self.topBar setHidden:YES];
}
}
-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[self.searchDisplayController.searchBar removeFromSuperview];
CGRect frame = self.searchDisplayController.searchBar.frame;
frame.origin.y += self.topBar.frame.size.height;
self.searchDisplayController.searchBar.frame = frame;
[self.topView addSubview:self.searchDisplayController.searchBar];
[self.topView bringSubviewToFront:self.topBar];
[self.topBar setHidden:NO];
}
}
我该如何解决这个问题?
最佳答案
尝试在您的 TableView Controller 中设置此值:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]){
self.edgesForExtendedLayout = UIRectEdgeNone;
}
并更改您的 View 层次结构以拥有一个 View 、tableView、搜索栏和 nag 栏作为其 subview 。使您的 TableView Controller 成为 View Controller ,并将其作为数据源和委托(delegate)。
或者不使用 searchBarDisplayController 而只使用带有委托(delegate)方法的搜索栏:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
关于ios - UISearchDisplayController 搜索栏重叠导航栏并自行调整大小 IOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19818998/