键盘高度

来源:互联网 发布:免费人才库软件 编辑:程序博客网 时间:2024/04/29 21:13

#pragma mark - 键盘设置

-(void)viewWillAppear:(BOOL)animated

{

    [selfregisterForKeyboardNotifications];

}

-(void)viewWillDisappear:(BOOL)animated

{    

[[NSNotificationCenterdefaultCenter]removeObserver:self];

}

- (void)registerForKeyboardNotifications

{

    //使用NSNotificationCenter键盘出现

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWasShown:)name:UIKeyboardDidShowNotificationobject:nil];

    //使用NSNotificationCenter鍵盤隐藏

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWillBeHidden:)name:UIKeyboardWillHideNotificationobject:nil];

}

//实现当键盘出现的时候计算键盘的高度大小。用于输入框显示位置

- (void)keyboardWasShown:(NSNotification*)aNotification

{

    NSDictionary* info = [aNotificationuserInfo];

    //kbSize即键盘尺寸 (width, height)

    CGSize kbSize = [[infoobjectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;//得到键盘的高度

    self.inputView.bottom =SCREENHEIGHT-1.23*kbSize.height;

    NSLog(@"hight_hitht:%f",kbSize.height);

}

//当键盘隐藏的时候

- (void)keyboardWillBeHidden:(NSNotification*)aNotification

{

    //do something

}


0 0
原创粉丝点击