简体   繁体   English

内容插入以在键盘出现时移动表格视图

[英]content inset to move the table view when keyboard appears

im stuck with a simple issue of moving my tableview when the keyboard shows. 我坚持一个简单的问题,当键盘显示时移动我的tableview。 i dont want to move the frame using animations, instead i want to use content inset to move the table view. 我不想使用动画移动框架,而是我想使用内容插入来移动表格视图。

my notification is being called bt it doesnt move the tableview. 我的通知被称为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");
}

What I believe you try to do here is making the scroll area of the table smaller in order to not have the keyboard overlap the table. 我相信你在这里尝试做的是使表的滚动区域更小,以便不使键盘与表重叠。 In that case, maybe you should put 在那种情况下,也许你应该放

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

instead of keyboardBounds.size.width . 而不是keyboardBounds.size.width If you want to "move" the table, then you can do that only by modifying its frame.origin or its center . 如果你想“移动”表格,那么你只能通过修改它的frame.origin或它的center来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM