美文网首页
键盘事件

键盘事件

作者: 陈世美_ | 来源:发表于2015-08-11 14:16 被阅读49次

    [[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];

    相关文章

      网友评论

          本文标题:键盘事件

          本文链接:https://www.haomeiwen.com/subject/pkyiqttx.html