2014-09-11 63 views
0

在我的代碼中,每當鍵盤彈出時,tableView都會被向上推,所以我可以看到tableView的底部。但是前三名或四名細胞將隱藏在視野之後。當鍵盤不在時,scrollView的頂部似乎被切斷。ios keyBoardShow with UITableView

我怎樣才能讓我的桌面查看完成時看到發短信?

這裏是我的代碼...

-(void)viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:animated]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil]; 
} 
-(void)keyboardShow:(NSNotification *)note{ 
    CGRect keyBoardRect=[note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; 
    CGFloat deltaY=keyBoardRect.size.height; 

    [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{ 
    self.view.transform=CGAffineTransformMakeTranslation(0, -deltaY); 
    }]; 
} 
-(void)keyboardHide:(NSNotification *)note{ 
    [UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{ 
    self.view.transform = CGAffineTransformIdentity; 
    }]; 
} 

滾動至底部添加一個文本到小區之後。

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(self.data.count-1) inSection:0]; 
[self.tableView beginUpdates]; 
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight]; 
[self.tableView endUpdates]; 
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 

回答

1

而不是轉換視圖時鍵盤顯示,通過調整其邊框縮小它:

CGRect newFrame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height-deltaY); 
self.view.frame = newFrame; 
+0

是的,你是對的。我認爲你的意思是使用「CGRectMake」代替。它的作品:)謝謝! – Jenny 2014-09-12 01:45:54