当键盘出现时,通过插入内容来移动表格视图

3

我遇到了一个简单的问题,当键盘弹出时,无法移动我的表格视图。我不想使用动画来移动框架,而是想使用内容插入来移动表格视图。

我的通知被调用了,但它没有移动表格视图。

- (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");
}
1个回答

2
我认为你想做的是缩小表格的滚动区域,以避免键盘覆盖表格。如果是这样,也许你应该放置


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

如果你想“移动”表格,那么只能通过修改其frame.origincenter来实现,而不是使用keyboardBounds.size.width


我有高度.. 我写了宽度来测试其他东西,不小心复制到这里了.. 我只使用高度,但仍然不起作用。 - Anshuk Garg
我不确定,NSValue是否能给你正确的键盘高度(应该是216);如果不行,你可以尝试这样做:NSNumber *keyboardHeight = [NSNumber numberWithFloat:[[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height]; - Demz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接