2012-03-16 30 views
3

當鍵盤顯示時,我遇到一個移動桌面視圖的簡單問題。 我不想移動框架使用動畫,而是我想使用內容插入移動表視圖。當鍵盤出現時移動桌面視圖的內容插入

我的通知被稱爲bt它不移動tableview。

- (void)keyboardWillShow:(NSNotification *)notification { 
NSLog(@"%@",self.tableView1); 

    NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]; 

    CGRect keyboardBounds; 
    [keyboardBoundsValue getValue:&keyboardBounds]; 
    UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0); 
NSLog(@"%d %d %d %d",self.tableView1.contentInset.bottom,self.tableView1.contentInset.top,self.tableView1.contentInset.left,self.tableView1.contentInset.right);  
    [self.tableView1 setContentInset:e]; 
    [self.tableView1 setScrollIndicatorInsets:e]; 
    NSLog(@"%d %d %d %d",self.tableView1.contentInset.bottom,self.tableView1.contentInset.top,self.tableView1.contentInset.left,self.tableView1.contentInset.right); 

NSLog(@"%@",self.tableView1); 
NSLog(@"keyboard notification"); 
} 

回答

2

我相信你在這裏試圖做的是讓桌面的滾動區域變小以免鍵盤重疊桌子。在這種情況下,也許你應該把

UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0); 

而不是keyboardBounds.size.width。如果您想「移動」表格,那麼只能通過修改其frame.origin或其center來完成此操作。

+0

我有身高..我寫了寬度來測試別的東西,錯誤的是在這裏複製..即時通訊只使用高度,仍然沒有工作。 – 2012-03-16 15:14:28

+0

我不確定,nsvalue是否給你正確的鍵盤高度(應該是216);如果沒有,你可以嘗試像這樣NSNumber * keyboardHeight = [NSNumber numberWithFloat:[[[通知userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue] .size.height]; – Demz 2012-03-16 15:32:15

相關問題