CYC-UISearchBar 点击空白回收键盘
来源:互联网 发布:知乎ios源码 编辑:程序博客网 时间:2024/06/06 02:44
ios--系统发出的通知--键盘通知// 监听键盘将要显示的通知 如果要显示 那么用keyboardWillShow来响应// 使用时注意 当这个页面消失的时候 立马移除所有监听- (void)viewDidLoad {// 添加通知 执行键盘回收 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)name:@"UIKeyboardWillHideNotification"object:nil]; [super viewDidLoad];}
#pragma mark - 表头添加searchBar- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ SeacherView *seacherView = [[SeacherView alloc]init]; seacherView.tag =100; seacherView.seachBar.delegate = self; seacherView.seachBar.showsBookmarkButton = NO; self.tableView.tableHeaderView = seacherView; return seacherView;}// 添加搜索框:- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{ [searchBar setShowsCancelButton:YES animated:NO]; // 让tableView 下拉 交换 为 NO self.tableView.allowsSelection = NO; self.tableView.scrollEnabled = NO; // 添加蒙版 UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)]; aView.backgroundColor = [UIColor clearColor]; aView.alpha = 0.1; [self.view addSubview:aView]; aView.tag = 10;}// 添加Cancel:- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ searchBar.text = @""; [searchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; self.tableView.allowsSelection = YES; self.tableView.scrollEnabled = YES; UIView *aView = [self.view viewWithTag:10]; // 移除蒙版 [aView removeFromSuperview];}// 添加搜索- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [searchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; self.tableView.scrollEnabled = YES; self.tableView.allowsSelection = YES; self.tableView.allowsSelection = YES; self.tableView.scrollEnabled = YES; UIView *aView = [self.view viewWithTag:10]; [aView removeFromSuperview]; // 点击搜索 把输入的字传到下个界面 SeacherViewController *seacherVC = [[SeacherViewController alloc] init]; NSString *nameStr = searchBar.text; seacherVC.name = nameStr; self.tabBarController.tabBar.hidden = YES; [self.navigationController pushViewController:seacherVC animated:YES];}
#pragma mark - 键盘回收- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObject]; // 计算搜索框范围 范围内不执行方法 之外执行键盘回收 CGPoint touchPoint = [touch locationInView:self.view]; if (touchPoint.x > 50 && touchPoint.x < kScreenWidth - 100 && touchPoint.y > 10 && touchPoint.y < 40) { NSLog(@"x = %f, y = %f", touchPoint.x, touchPoint.y); } else { [self.view endEditing:YES]; }}#pragma mark - 通知方法执行 移除蒙版 还有 点击方法- (void)keyboardWillHide:(NSNotification *)notification{ UIView *aView = [self.view viewWithTag:10]; [aView removeFromSuperview]; SeacherView *seacherView = (SeacherView *)[self.view viewWithTag:100]; [seacherView.seachBar setShowsCancelButton:NO animated:YES]; [seacherView.seachBar resignFirstResponder]; self.tableView.allowsSelection = YES; self.tableView.scrollEnabled = YES;}
0 0
- CYC-UISearchBar 点击空白回收键盘
- 点击空白回收键盘
- 点击空白处,回收键盘
- 点击空白处回收键盘
- 点击空白处回收键盘整理
- iOS点击空白处回收键盘
- swift3.0 点击空白处回收键盘
- 点击屏幕空白实现键盘回收的几种方法
- 点击return和空白回收键盘跳到下一个
- iOS新手入门之点击空白处回收键盘
- 小知识4 在根视图上设置回收键盘响应,点击空白处回收键盘
- 点击空白隐藏键盘
- 点击空白关闭键盘
- 点击空白关闭键盘
- 点击空白关闭键盘
- iOS点击空白处和和return键,回收键盘,隐藏键盘
- 牛逼,点击空白处回收键盘,设置view的大小,视图控制器(特别重要)
- 键盘遮点击空白挡回收自动处理的第三方库 IQKeyboardManager
- JDK1.8中 接口成员变量和成员方法
- October——I Will Talk
- Interleaving String
- Matlab中graphmaxflow函数的用法
- UILabel自动适应尺寸
- CYC-UISearchBar 点击空白回收键盘
- 部署redis集群的一些思考
- 总结的一些Java公用函数库(各种Utils)
- NSRunLoop详解
- android 布局管理器 各种布局简介
- 基于opencv的相机之最初布局(一)
- 夏洛特的网 ——看《夏洛特的网》
- 欢迎使用CSDN-markdown编辑器
- 发现翻-强的一个不错的选择,感觉不不错,分享