我的应用程序有一个表格视图控制器,它显示为表单。
在 tableviewcontoller 的顶部有一个 UView,在该 UIView 内部有一个导航栏和一个搜索栏。
旧版本的 IOS 一切正常,但在 IOS7 中,当用户点击搜索栏时,一切都一团糟。
普通的:
当用户开始键入时:
搜索结束后:
在.h
UITableViewController<UITextFieldDelegate,UISearchDisplayDelegate,UISearchBarDelegate>
@property (nonatomic,weak) IBOutlet UINavigationBar *topBar;
尝试了几件事,但代码似乎没有改变任何东西,当放置一个断点时,它进入委托方法
英寸
//-(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 at all
我也试过
-(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];
}
}
我该如何解决这个问题?