searchDisplayControllerWillEndSearch 不调整搜索栏大小

发布于 2024-12-28 16:09:20 字数 2163 浏览 0 评论 0原文

只是想知道为什么并且需要解决它。我的搜索栏看起来像这样。 单击的 在此处输入图像描述

将移动到顶部并扩展到 0,0,320,搜索栏的高度。

在此处输入图像描述

单击“取消”,它应该调整回搜索栏的高度 33,55,270。但它不会

在此处输入图像描述

searchDisplayControllerDidEndSearch 将调整大小,但是用户会出现 1 秒的延迟可以看到变化。为什么在 searchDisplayControllerWillEndSearch 中动画调整伤口大小不起作用?

感谢您的评论和反馈。

- (void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{

    [UIView animateWithDuration:.1
                     animations:^{ 

    controller.searchResultsTableView.frame = frogTableView.frame;
    searchDisplayController.searchResultsTableView.frame = frogTableView.frame;

    searchDisplayController.searchBar.frame = CGRectMake(32,
                                                         55,
                                                         270,
                                                         searchDisplayController.searchBar.frame.size.height);

    searchBar.frame = CGRectMake(32,
                                 55,
                                 270,
                                 searchBar.frame.size.height);
                         frogTableView.frame = CGRectMake(frogTableView.frame.origin.x, 
                                                          121, 
                                                          frogTableView.frame.size.width, 
                                                          frogTableView.frame.size.height);

                         notePad.frame = CGRectMake(notePad.frame.origin.x, 
                                                    45, 
                                                    notePad.frame.size.width, 
                                                    notePad.frame.size.height);

                         searchDisplayController.searchResultsTableView.frame = frogTableView.frame;
                      } 
                     completion:^(BOOL finished){
                         //whatever else you may need to do

                     }];
}

Just wondering why and need to solve it. i have this searchbar looks like this.
enter image description here

which clicked will move up to the top and expend to 0,0,320,searchbar's height.

enter image description here

which clicked Cancel, it should resize back to 33,55,270, searchbar's height. but it doesn't

enter image description here

the searchDisplayControllerDidEndSearch will work to resize back, however there is a 1 sec lag that user could see the changes. any body why in searchDisplayControllerWillEndSearch the animation resize wound't work ?.

thanks for the comments and feedback.

- (void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{

    [UIView animateWithDuration:.1
                     animations:^{ 

    controller.searchResultsTableView.frame = frogTableView.frame;
    searchDisplayController.searchResultsTableView.frame = frogTableView.frame;

    searchDisplayController.searchBar.frame = CGRectMake(32,
                                                         55,
                                                         270,
                                                         searchDisplayController.searchBar.frame.size.height);

    searchBar.frame = CGRectMake(32,
                                 55,
                                 270,
                                 searchBar.frame.size.height);
                         frogTableView.frame = CGRectMake(frogTableView.frame.origin.x, 
                                                          121, 
                                                          frogTableView.frame.size.width, 
                                                          frogTableView.frame.size.height);

                         notePad.frame = CGRectMake(notePad.frame.origin.x, 
                                                    45, 
                                                    notePad.frame.size.width, 
                                                    notePad.frame.size.height);

                         searchDisplayController.searchResultsTableView.frame = frogTableView.frame;
                      } 
                     completion:^(BOOL finished){
                         //whatever else you may need to do

                     }];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

安穩 2025-01-04 16:09:20

当我开始使用 UISearchBar 和 UISearchDisplayController 后,我遇到了同样的问题。我想出的解决方案是将搜索栏放在视图上:

UIView * searchBarSubview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MENU_WORK_AREA_WIDTH, SEARCH_BAR_HEIGHT)] ;
searchBarSubview.autoresizesSubviews = YES;
searchBarSubview.backgroundColor = [UIColor clearColor];

UISearchBar * globalSearchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, MENU_WORK_AREA_WIDTH, SEARCH_BAR_HEIGHT)] autorelease];
globalSearchBar.tintColor = [UIColor blackColor];
globalSearchBar.delegate = self;
[globalSearchBar setBackgroundImage:[UIImage alloc]];

并调整视图的大小,而不是在 searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller 中调整搜索栏:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

// Slide in to the final destination
searchBarSubview.frame = CGRectMake(0, 0, MENU_WORK_AREA_WIDTH, SEARCH_BAR_HEIGHT);

[UIView commitAnimations];

I had the same trouble after I started to use UISearchBar with UISearchDisplayController. The solution I came up with is to place a search bar on a view:

UIView * searchBarSubview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MENU_WORK_AREA_WIDTH, SEARCH_BAR_HEIGHT)] ;
searchBarSubview.autoresizesSubviews = YES;
searchBarSubview.backgroundColor = [UIColor clearColor];

UISearchBar * globalSearchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, MENU_WORK_AREA_WIDTH, SEARCH_BAR_HEIGHT)] autorelease];
globalSearchBar.tintColor = [UIColor blackColor];
globalSearchBar.delegate = self;
[globalSearchBar setBackgroundImage:[UIImage alloc]];

and resize the view instead of search bar in searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

// Slide in to the final destination
searchBarSubview.frame = CGRectMake(0, 0, MENU_WORK_AREA_WIDTH, SEARCH_BAR_HEIGHT);

[UIView commitAnimations];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文