iOS 监测键盘消失,出现

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

- (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);

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 这篇文章会对 IQKeyboardManager 自动解决键盘遮挡问题的方法进行分析。 最近在项目中使用了 IQK...
    MissLu16阅读 2,534评论 0 4
  • iphone开发笔记 退回输入键盘 - (BOOL) textFieldShouldReturn:(id)text...
    爱易寒曲易散阅读 629评论 0 1
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 833评论 0 0
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,538评论 1 14
  • 外出,同住的一个哥们名字里有一个乐字,他年纪比我小,且称之为阿乐。 几乎一见面我就欢喜他。有着170斤的体重,看上...
    斯夜寒阅读 205评论 0 1