键盘事件
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(actionKeyboardShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(actionKeyboardHide:)
name:UIKeyboardWillHideNotification
object:nil];
- (void)actionKeyboardShow:(NSNotification*)notification
{
CGSizekeyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size
self.tableView.frame=CGRectMake(0,0,320,self.view.h-keyboardSize.height);
if( v )
{
while( ![v isKindOfClass:[UITableViewCell class]]) {
v = v.superview;
}
UITableViewCell*cell = (UITableViewCell*)v;
[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForRowAtPoint:cell.center] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
}
获取当前正在输入的控件
static __weak id currentFirstResponder;
+(id)currentFirstResponder {
currentFirstResponder =nil;
[[UIApplication sharedApplication] sendAction:@selector(findFirstResponder:) to:nil from:nil forEvent:nil];
returncurrentFirstResponder;
}
-(void)findFirstResponder:(id)sender {
currentFirstResponder =self;
}
键盘消失三种做法
[someView resignFirstResponder];
[self.view endEditing:YES];
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];