我遇到搜索欄時出現問題,當它變爲firstResponder
並且它辭職時,它會以一種奇怪的方式運行。UISearchBar自動調整大小和更改框架
搜索欄被添加爲
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;
}
正常狀態
當搜索欄變成firstResponder
個它圍繞一個點了無論是移動還是向下指向隨機
而當搜索欄辭職它動畫最多,達到窗口原點,然後返回到其自然框架
這是一個sample project重現錯誤。
編輯:
按@kwylezsuggestion,不必要的動畫時,如果辭職可以通過避免搜索欄的:
self.searchBar.clipsToBounds = YES;
將您的搜索欄作爲視圖控制器的視圖的子視圖,而不是作爲的tableView的的tableHeader修復向上/向下運動,如果沒有必須的tableHeader。 –
這是真的,但我有內容背後的表格視圖,需要顯示時,用戶滾動......我可能會回到解決方案,雖然如果我沒有找到任何東西。 – Moxy
查看我的回答 – codercat