ios开发 解决键盘弹起遮盖输入框的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ljc_563812704/article/details/84327268

该方法只针对tableViewCell上的输入框有效,其他的可以通过获取键盘高度,向上移动控件

1.注册监听

- (void)registerForKeyboardNotifications

{

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

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

}

2.监听执行方法

- (void)keyboardWasShow:(NSNotification *)aNotification

{

        NSDictionary *info = [aNotification userInfo];

        CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

     //非tablView 通过获取键盘高度,向上移动控件

        self.talbleViewList.contentInset= UIEdgeInsetsMake(0,0, kbSize.height,0); 

}

- (void)keyboardWasHidden:(NSNotification *)aNotification

{

    self.talbleViewList.contentInset= UIEdgeInsetsMake(0,0, 0,0);

}

猜你喜欢

转载自blog.csdn.net/ljc_563812704/article/details/84327268