我在搜索栏下面有一个带有tableView的搜索栏。我想去全屏时,用户点击搜索栏进行搜索。但我无法将框架设置为UISearchBar的起源。我就是这样做的。
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[ [UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[self.topBarView setHidden:YES];
[UIView animateWithDuration:1.0
delay:0.0
options:0
animations:^{
[self.searchBar setFrame:CGRectMake(0.0,0.0, self.searchBar.frame.size.width,
self.searchBar.frame.size.height )];
}
completion:^(BOOL completion){
}];
[self.searchBar setNeedsDisplay];
}}


我隐藏了搜索栏上方的所有视图,并在第二张图像中将原点设置为0,0,顶部栏消失,但搜索栏停留在其位置上。它应该在顶部。如果有人能发现这个问题,那就太好了。,我也在使用自动布局,这会引起什么问题吗?
发布于 2014-02-12 12:00:21
使用搜索栏显示controller.it将实现这一目标。

发布于 2014-02-12 12:18:09
尝尝这个。向控制器中添加搜索栏和searchDisplay控制器。
UISearchBar *searchBar;UITableView *tableView;UISearchDisplayController *searchController;
// Create table view
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[self.view addSubview:_tableView];
// Create search bar
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, 44.0f)];
_searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
_searchBar.delegate = self;
[self.view addSubview:_searchBar];
[_searchBar sizeToFit];
// Create search controller
_searchController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
_searchController.searchResultsDataSource = self;
_searchController.searchResultsDelegate = self;
_searchController.delegate = self;然后您可以执行此操作,以便searchBar成为响应者&显示键盘。
[_searchBar becomeFirstResponder];希望这能有所帮助。
https://stackoverflow.com/questions/21727097
复制相似问题