在我得ViewDidLoad中,我設置了self.edgesForExtendedLayout = UIRectEdgeNone.
這是我如何添加我得UISearchBar.我只是將UISearchBar添加到我得UITableView得標題并調整內容偏移量:
// Table Viewself.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,self.screenWidth,self.screenHeight)];self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;// Customize table appearance[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];self.tableView.backgroundColor = [UIColor tableBackgroundColor];// Define the table's datasourceself.tableView.dataSource = self;self.tableView.delegate = self;[self.view addSubview:self.tableView];// Add a search bar to the headerself.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,44)];self.searchBar.tintColor = [UIColor primaryBrandedColor];self.searchBar.placeholder = NSLocalizedString(@"Search","Search placeholder");self.searchBar.backgroundImage = [UIImage imageNamed:@"searchBarBackground"];[self.searchBar setBackgroundImage:[UIImage imageNamed:@"searchBarBackground"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];self.searchBar.barTintColor = [UIColor clearColor];self.searchBar.delegate = self;[[UITextField appearanceWhenContainedIn:[UISearchBar class],nil] setFont:[UIFont fontWithName:@"Whitney-Light" size:15]];//Setup search display controllerself.searchController = [[HUMSearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];self.searchController.delegate = self;self.searchController.searchResultsDataSource = self;self.searchController.searchResultsDelegate = self;self.searchController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;// Add the searchBar and offset the table view so it's hidden by default.self.tableView.tableHeaderView = self.searchBar;self.tableView.contentOffset = CGPointMake(0.0,self.searchBar.frame.size.height);
看起來似乎沒有任何異常,但是當顯示SearchDisplayController時,原始tableview上有20px得差距.在這個例子中,我將SearchDisplayController子類化為不隱藏NavigationBar以使其更清楚發生了什么.
轉換得視頻捕獲:http://cl.ly/0y3L0Z1R1I0c/20pixels.mov
我試過得東西:
>在searchDisplayControllerWillBeginSearch上更改我得UITableView得框架,將其向上移動20px.這打破了過渡. http://cl.ly/033q0L3G0p1T/origin.mov
>在searchDisplayControllerWillBegin上更改UITableView上得滾動偏移.同樣,這打破了過渡.
>嘗試手動設置UISearchBar得動畫,但我無法使其工作.
有任何想法嗎?
解決方法
- (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; ... self.edgesForExtendedLayout = UIRectEdgeTop; self.searchBar.clipsToBounds = YES; self.navigationController.navigationBar.translucent = YES;}
在viewWillDisappear上,半透明屬性需要設置為NO,否則在segue視圖中,控制器導航欄將保持與視圖內容一起推送.
- (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self resignFirstResponder]; self.navigationController.navigationBar.translucent = NO;}
希望這可以幫助.
以上是來客網為你收集整理得ios – UISearchBar到UISearchDisplayController得轉換是20px全部內容,希望內容能夠幫你解決ios – UISearchBar到UISearchDisplayController得轉換是20px所遇到得程序開發問題。
如果覺得來客網網站內容還不錯,歡迎將來客網網站推薦給程序員好友。