我正在iOS中构建评论屏幕。我有主视图,该主视图具有用于显示先前评论的表格视图和用于发布评论的文本字段。当键盘抬起时主视图向上移动时,我将无法从中滚动表格视图屏幕的顶部。初始注释不可见。请告诉我们如何在表格视图中设置滚动视图的偏移量?

向上移动表格视图的代码

- (void)keyboardWillShow:(NSNotification*)notification
{
    NSDictionary *info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    // Write code to adjust views accordingly using deltaHeight
    _currentKeyboardHeight = kbSize.height;
    self.nslc_view_top.constant=-_currentKeyboardHeight;
    self.nslc_view_bottom.constant=_currentKeyboardHeight;
    [self.view_container layoutSubviews];




}

最佳答案

我不清楚您的问题,但您可以像这样将表格视图滚动到顶部;

self.tableView.setContentOffset(CGPointZero, animated:true)


如果您的表格视图包含整个屏幕,则可能不起作用。然后尝试;

let indexPath = NSIndexPath(forRow: 0, inSection: 0)
self.tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .Top, animated: true)


如果您的tableView有标题,您也可以尝试;

self.tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated: true)

07-26 09:37
查看更多