Skip to content

Commit

Permalink
Fixed #49 the display of view when navigationBar.translucent is NO
Browse files Browse the repository at this point in the history
Fixed the display of view when navigationBar.translucent is NO
  • Loading branch information
ko1o committed Feb 11, 2017
1 parent e76d425 commit 22ac65b
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions PYSearch/PYSearchViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@ - (void)awakeFromNib
[self setup];
}

/** 视图完全显示 */
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

// 弹出键盘
[self.searchBar becomeFirstResponder];
}

/** 视图即将显示 */
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

// 根据navigationBar.translucent属性调整视图
self.baseSearchTableView.contentInset = UIEdgeInsetsMake(64 - self.view.py_y, 0, self.view.py_y, 0);
self.navigationController.navigationBar.barTintColor = PYSEARCH_COLOR(249, 249, 249);
}

/** 视图即将消失 */
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

// 回收键盘
[self.searchBar resignFirstResponder];
}

/** 控制器销毁 */
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

+ (instancetype)searchViewControllerWithHotSearches:(NSArray<NSString *> *)hotSearches searchBarPlaceholder:(NSString *)placeholder
{
PYSearchViewController *searchVC = [[PYSearchViewController alloc] init];
Expand Down Expand Up @@ -116,7 +150,7 @@ - (PYSearchSuggestionViewController *)searchSuggestionVC
[_weakSelf searchBarSearchButtonClicked:_weakSelf.searchBar];
}
};
searchSuggestionVC.view.frame = CGRectMake(0, 64, self.view.py_width, self.view.py_height);
searchSuggestionVC.view.frame = CGRectMake(0, 64 - self.view.py_y, self.view.py_width, self.view.py_height + self.view.py_y);
searchSuggestionVC.view.backgroundColor = self.baseSearchTableView.backgroundColor;
searchSuggestionVC.view.hidden = YES;
// 设置数据源
Expand Down Expand Up @@ -199,31 +233,6 @@ - (UIBarButtonItem *)cancelButton
return self.navigationItem.rightBarButtonItem;
}

/** 视图完全显示 */
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

// 弹出键盘
[self.searchBar becomeFirstResponder];
}

/** 视图即将消失 */
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];

// 回收键盘
[self.searchBar resignFirstResponder];
}


/** 控制器销毁 */
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

/** 初始化 */
- (void)setup
{
Expand Down Expand Up @@ -310,12 +319,12 @@ - (void)setup
emptySearchHistoryLabel.userInteractionEnabled = YES;
emptySearchHistoryLabel.text = [NSBundle py_localizedStringForKey:PYSearchEmptySearchHistoryText];
emptySearchHistoryLabel.textAlignment = NSTextAlignmentCenter;
emptySearchHistoryLabel.py_height = 30;
emptySearchHistoryLabel.py_height = 49;
[emptySearchHistoryLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(emptySearchHistoryDidClick)]];
emptySearchHistoryLabel.py_width = PYScreenW;
self.emptySearchHistoryLabel = emptySearchHistoryLabel;
[footerView addSubview:emptySearchHistoryLabel];
footerView.py_height = 30;
footerView.py_height = emptySearchHistoryLabel.py_height;
self.baseSearchTableView.tableFooterView = footerView;

// 默认没有热门搜索
Expand Down Expand Up @@ -1130,6 +1139,11 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
return self.searchHistories.count && self.showSearchHistory ? 44 : 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Expand Down

0 comments on commit 22ac65b

Please sign in to comment.