我有一个搜索栏的问题,当它变成a firstResponder
并且它何时退出时,它会以一种奇怪的方式运行.
搜索栏将添加为表视图的标题
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)]; self.searchBar.translucent = NO; self.searchBar.barTintColor = [UIColor grayColor]; self.tableView.tableHeaderView = self.searchBar; self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; self.searchController.searchResultsDataSource = self;
视图控制器设置为左侧面板,JASidePanelController
当键盘显示或隐藏时,它会隐藏中央面板:
- (void)keyboardWillAppear:(NSNotification *)note { [self.sidePanelController setCenterPanelHidden:YES animated:YES duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; self.searchBar.showsCancelButton = YES; } - (void)keyboardWillDisappear:(NSNotification *)note { [self.sidePanelController setCenterPanelHidden:NO animated:YES duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]]; self.searchBar.showsCancelButton = NO; }
正常状态
当搜索栏变为a时,firstResponder
它会向上移动一个点或随机向下移动
当搜索栏退出时,它会动画到达窗口原点,然后返回其自然帧
这是一个重现错误的示例项目.
编辑:
根据@kwylez的 建议,可以通过以下方式避免搜索栏在重新签名时产生的不需要的动画:
self.searchBar.clipsToBounds = YES;
小智.. 8
我通过创建一个ClipBounds设置为YES的UIView解决了这个问题,然后在其中添加了子视图搜索栏.然后将其包含在tableview标题中.它现在正在工作.
谢谢
我通过创建一个ClipBounds设置为YES的UIView解决了这个问题,然后在其中添加了子视图搜索栏.然后将其包含在tableview标题中.它现在正在工作.
谢谢