DJSelectCityViewController.m

/** SearchBar开始编辑 */
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {

    // 隐藏导航栏
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    // 显示遮罩
    UIView *cover = [[UIView alloc] init];
    cover.backgroundColor = [UIColor blackColor];
    cover.alpha = 0.2;
    cover.frame = self.cityTableView.frame;
    cover.tag = DJCoverTag;
    
    // 由于UIView 不是UIControl,所以没有addTarget方法,可以使用UITapGestureRecognizer代替
    // 当conver被点击时,移除第一响应者
    [cover addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:searchBar action:@selector(resignFirstResponder)]];
    
    [self.view addSubview:cover];

}


/** SearchBar结束编辑 */
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {

    // 显示导航栏
    [self.navigationController setNavigationBarHidden:NO animated:YES];

    // 隐藏遮罩
    [[self.view viewWithTag:DJCoverTag] removeFromSuperview];
    
}

 

最终效果:

美团HD(6)-添加搜索遮罩

 

相关文章:

  • 2022-02-24
  • 2022-01-05
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-11-16
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案