首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变换UISearchbar

变换UISearchbar
EN

Stack Overflow用户
提问于 2014-02-12 11:48:00
回答 2查看 234关注 0票数 0

我在搜索栏下面有一个带有tableView的搜索栏。我想去全屏时,用户点击搜索栏进行搜索。但我无法将框架设置为UISearchBar的起源。我就是这样做的。

代码语言:javascript
复制
-(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,顶部栏消失,但搜索栏停留在其位置上。它应该在顶部。如果有人能发现这个问题,那就太好了。,我也在使用自动布局,这会引起什么问题吗?

EN

回答 2

Stack Overflow用户

发布于 2014-02-12 12:00:21

使用搜索栏显示controller.it将实现这一目标。

票数 0
EN

Stack Overflow用户

发布于 2014-02-12 12:18:09

尝尝这个。向控制器中添加搜索栏和searchDisplay控制器。

UISearchBar *searchBar;UITableView *tableView;UISearchDisplayController *searchController;

代码语言:javascript
复制
 // 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成为响应者&显示键盘。

代码语言:javascript
复制
[_searchBar becomeFirstResponder];

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21727097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档