我的聊天应用程序遇到了一些小问题,该应用程序由表格视图和文本字段组成。当我点击文本字段时,键盘会弹出并向上推表格视图和文本字段,以便我可以键入消息。但是,由于表视图上升了,因此,一旦我发送了消息,该消息就会显示在表视图的第一个单元格中,并最终由于隐藏而隐藏起来,除非我隐藏了键盘。你们认为这样做的正确方法是什么?我认为文本字段应该是我扩展键盘时唯一向上移动的东西,而不是整个视图?有人做过类似的事情吗?

这是我用来调整视图的代码

- (void)moveView:(NSDictionary*)userInfo up:(BOOL)up
{
    CGRect keyboardEndFrame;
    [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]
     getValue:&keyboardEndFrame];

    UIViewAnimationCurve animationCurve;
    [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey]
     getValue:&animationCurve];

    NSTimeInterval animationDuration;
    [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey]
     getValue:&animationDuration];

    // Get the correct keyboard size to we slide the right amount.
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:animationDuration];
    [UIView setAnimationCurve:animationCurve];

    CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
    int y = keyboardFrame.size.height * (up ? -1 : 1);
    self.view.frame = CGRectOffset(self.view.frame, 0, y);

    [UIView commitAnimations];

}

最佳答案

上下移动文本字段,以及调整表格视图的大小以及显示/隐藏键盘,而不仅仅是上下移动整个视图。无论如何,您的整个表格视图都是可见的。

关于ios - 调整消息传递应用程序的 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22927692/

10-11 22:16
查看更多