首先在: viewWillAppear 方法添加通知
/**
视图将要出现时添加通知
*/
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];
}
只要键盘弹出就会调用:
#pragma mark 键盘弹出、收起action
- (void)keyboardShow:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyFrame = [value CGRectValue];
NSNumber *keyAnim = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
CGFloat duration = [keyAnim doubleValue];//系统键盘的高度
[self keyboardChangedHeight:keyFrame.size.height + 49.0 animation:duration];//因为有tabbar所以需要增加49
if (self.trackIndexPath) {
[self.tableView scrollToRowAtIndexPath:self.trackIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
}
- (void)keyboardHide:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
NSNumber *keyAnim = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
CGFloat duration = [keyAnim doubleValue];
[self keyboardChangedHeight:49.0f + 64.0f animation:duration];//因为有tabbar所以需要增加49
}
- (void)keyboardChangedHeight:(CGFloat)height animation:(CGFloat)duration
{
CGFloat backHeight = SIZE.height;
CGRect frame = self.tableView.frame;
frame.size.height = backHeight - height;
// NSLog(@"HEI%f=%f=%f",backHeight,height,backHeight - height);
[UIView animateWithDuration:duration animations:^{
self.tableView.frame = frame;
}];
}
以下是scrollViewDelegate 当View滑动的时候调用,在此添加隐藏键盘的方法。
#pragma mark scrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
//拖拽时收回键盘暂时
// [self.view endEditing:YES];
//
// [self.unFinishTextView resignFirstResponder];
// [self.lkmmanTextField resignFirstResponder];
// [self.lkmmobileTextField resignFirstResponder];
// [self.workTimeTextField resignFirstResponder];
// [self.egnnoTextField resignFirstResponder];
// [self.placeTemptTextView resignFirstResponder];
// [self.serviceContentTextView resignFirstResponder];
}
看到一个笑话:
女程序员发的一条微博:
“昨晚梦见男朋友和别的女人在逛街,梦里我的第一反应就是查源代码,结果调试半天查不出来为什么显示的那个女人不是我,最后含泪把那个女人注释掉了,再一运行就是我男朋友自己逛街了。” 众网友的神回复:
1、把那个女人的指针指向你即可; (:з」∠)
2、谁让你把男朋友设成public的?;Σ(っ °Д °;)っ
3、加个断点看看那女人是谁; (ಡωಡ)
4、心真软,就应该把他的接口屏蔽掉; (눈_눈)
5、Protected逛街(youOnly); (ง•̀_•́)ง
6、设计问题,应该采用单例模式; (๑•́ωก̀๑)
7、没做回归测试; ヽ(  ̄д ̄;)ノ
8、标准做法是做个断言; (๑•̀ㅂ•́) ✧
9、注释掉了,逛街的参数不用改吗?; (@ ̄ー ̄@)
10、最后含泪把那个女人给注释掉了,再一运行就是我男朋友自己逛街了—>很明显是变量名作用域的问题,改个名就行了(๑•̀ㅂ•́) ✧
11、还可以有个多线程的算法,把你的优先级设成99,一个idle线程的优先级设成50,把那个女人的优先级设成49。酱紫就永远都调度不到啦 (๑•́ωก̀๑)
12、那也没关系,那就老调用那个女人。。。你BF放在那里不动。。。养着 (ಡωಡ)
13、上绝招,用goto,做个死循环,让他们逛死 (๑•̀ㅂ•́) ✧
14、善心点,别goto了,调用exit函数结束进程吧,冤冤相报何时了啊 ヽ(  ̄д ̄;)ノ
15、查一下Log,仅仅只有逛街吗?ԅ(¯ㅂ¯ԅ)