当键盘处于活动状态时,UITableView向上移动
问题描述:
我有UITableView和UITextfields作为contentView中的子视图。当键盘处于活动状态时,UITableView向上移动
他们工作和所有,但是当我选择底部的,他们正在被键盘覆盖,所以我想UITableView向上滚动。
这里是我当前的代码:
-(void)keyboardWillShow:(NSNotification*)notification {
NSValue *keyboardFrameValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];
CGRect keyboardFrame = [[self view] convertRect:[keyboardFrameValue CGRectValue] fromView:nil];
[UIView animateWithDuration:0.3 animations:^{
[constraint setConstant:keyboardFrame.size.height];
[self.myTableView layoutIfNeeded];
}];
}
-(void)keyboardWillHide:(NSNotification *)notification {
[UIView animateWithDuration:0.3 animations:^{
[constraint setConstant:0];
[self.myTableView layoutIfNeeded];
}];
}
这里的问题是,它搅乱数据,文本框被添加到了错误的细胞和东西。
希望任何人都可以帮忙。
你为什么不使用第三方库? –
为什么? uitableview? –
你可以检查这..... ..... https://github.com/hackiftekhar/IQKeyboardManager或这.... https://github.com/michaeltyson/TPKeyboardAvoiding –