Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //UIView *_currentText;//当前编辑的textField
- - (void)textFieldDidBeginEditing:(UITextField *)textField {
- _currentText = textField;
- }
- - (void)keyboardWillShow:(NSNotification *)aNotification {
- //键盘高度
- NSDictionary* info = [aNotification userInfo];
- //kbSize即為鍵盤尺寸 (有width, height)
- CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;//得到鍵盤的高度
- UITableViewCell *cell = (UITableViewCell *)[_currentText superview];
- //将tableView里面的这个cell的Frame转化成tableView的父视图的相对位置
- //即cell在tableView的父视图的位置
- CGRect rect = [_table convertRect:cell.frame toView:[_table superview]];
- /*KHFullScreenHeight全屏高度
- * 64导航栏的加状态栏的高度
- * kbSize.height 键盘的高度
- * CGRectGetMaxY(rect) cell在tableView的父视图的位置的y+cell本身的height
- */
- CGFloat cj = (KHFullScreenHeight-64-kbSize.height) - (CGRectGetMaxY(rect));
- if (cj < 0) {
- //被键盘遮住
- //tableView上移动
- //cj差多少就移动多少
- [UIView animateWithDuration:0.3 animations:^{
- self.table.frame = CGRectMake(0, self.table.frame.origin.y+cj, self.table.frame.size.width, self.table.frame.size.height);
- }];
- }
- }
- - (void)keyboardWillHide {
- //tableView回到原本位置
- [UIView animateWithDuration:0.3 animations:^{
- self.table.frame =CGRectMake(0, 0, self.table.frame.size.width, self.table.frame.size.height);
- }];
- }
- //return键收起键盘
- - (BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement