美文网首页
iOS 监测键盘消失,出现

iOS 监测键盘消失,出现

作者: 花蕊1235 | 来源:发表于2017-12-19 11:33 被阅读0次

    //检测到有键盘的时候 页面上移

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    if (textField == nameTF) {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    }

    return YES;

    }

    - (void)keyboardWillShow:(NSNotification *)notification{

    whiteView.frame = CGRectMake(0,self.frame.size.height/16, self.frame.size.width/2, self.frame.size.height/8*3);

    }

    //键盘消失

    - (void)keyboardWillHide:(NSNotification *)notification {

    whiteView.frame =CGRectMake(0,self.frame.size.height/16*5, self.frame.size.width/2, self.frame.size.height/8*3);

    }

    相关文章

      网友评论

          本文标题:iOS 监测键盘消失,出现

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