Iphone searchDisplayControllerWillEndSearch未调整搜索栏的大小
只是想知道为什么,需要解决它。我有一个像这样的搜索栏。 点击后会向上移动到顶部,并扩展到0,0320,搜索栏的高度 如果单击“取消”,则应将其大小调整回33,55270,即搜索栏的高度。但事实并非如此 searchDisplayControllerDidEndSearch将重新调整大小,但是有一个1秒的延迟,用户可以看到更改。任何人为什么在searchDisplayControllerWillEndSearch中动画无法工作 感谢您的评论和反馈Iphone searchDisplayControllerWillEndSearch未调整搜索栏的大小,iphone,ios,uikit,uisearchbar,uisearchdisplaycontroller,Iphone,Ios,Uikit,Uisearchbar,Uisearchdisplaycontroller,只是想知道为什么,需要解决它。我有一个像这样的搜索栏。 点击后会向上移动到顶部,并扩展到0,0320,搜索栏的高度 如果单击“取消”,则应将其大小调整回33,55270,即搜索栏的高度。但事实并非如此 searchDisplayControllerDidEndSearch将重新调整大小,但是有一个1秒的延迟,用户可以看到更改。任何人为什么在searchDisplayControllerWillEndSearch中动画无法工作 感谢您的评论和反馈 - (void) searchDisplay
- (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
}];
}
在我开始将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*)控制器中调整视图而不是搜索栏的大小:
[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];
哦,为什么是街区?这通常只应用于GCD或更复杂的网络。你做得太过火了:Pso我应该怎么做Galaxas0?可能会使用-@Galaxas0-块的重复,这个问题与块无关。我知道,但它只是让代码变得更简单。