2

我试图完成UITextView类似于 Instagram 的评论。我之前使用UITableView并使用beginUpdatesendUpdates在用户输入评论时重新加载页脚大小。我collectionView尝试了几种不同的方法来重新加载页脚,但视图向上滚动到其原始位置,将 textView 隐藏在键盘下。我试图保留UITextView键盘上方并让它为每个新行扩展。

- (void)textViewDidChange:(UITextView *)textView{
        NSInteger numLines;
        numLines = textView.contentSize.height/textView.font.lineHeight;
        if (numLines > nextLine) {
            height = height + 15;
            [self.collectionView.collectionViewLayout invalidateLayout];
            [footer.commentTextView becomeFirstResponder];
            CGPoint scrollPt = CGPointMake(0, 300);
            [self.collectionView setContentOffset:scrollPt animated:NO];

            nextLine = numLines;
   }
}

 - (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    return CGSizeMake(320, height);
}
4

0 回答 0