Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios uiCollectionViewCell调整单元格大小_Ios_Uitextview_Uicollectionview - Fatal编程技术网

Ios uiCollectionViewCell调整单元格大小

Ios uiCollectionViewCell调整单元格大小,ios,uitextview,uicollectionview,Ios,Uitextview,Uicollectionview,当用户在编写时UICollectionView中的UITextView变大时,我不知道如何调整UICollectionView中的单元格大小(就像我在下面的代码中所做的那样:) 我想使包含此UITextView的项单元格相对于UITextView变大/变小。我无法通过笔划单元格的新高度和使用重载数据来更改大小,因为这会使键盘消失,用户无法再写了。我不确定,但我认为您可以尝试使布局无效,并强制重新绘制uicollectionview布局 看看这个:是的,我之前看过那篇文章。我尝试过,但不幸的是,如

当用户在编写时UICollectionView中的UITextView变大时,我不知道如何调整UICollectionView中的单元格大小(就像我在下面的代码中所做的那样:)


我想使包含此UITextView的项单元格相对于UITextView变大/变小。我无法通过笔划单元格的新高度和使用重载数据来更改大小,因为这会使键盘消失,用户无法再写了。

我不确定,但我认为您可以尝试使布局无效,并强制重新绘制uicollectionview布局


看看这个:

是的,我之前看过那篇文章。我尝试过,但不幸的是,如果在用户仍在写入时调用invalidateLayout,这将影响写入…有没有办法在没有UITextView的情况下实现相同的结果(即:有一个UICollectionView,其中单元格包含使单元格适合文本大小的文本)?因为,UITextView不应该随着内容的增长而增长,对吗?如果您试图增加单元格大小,这意味着您试图更改集合视图的当前布局,则需要调用invalidateLayout,从而关闭键盘。相反,你可以设置弹出窗口的动画,接收用户输入,然后根据单元格的内容重新绘制整个布局。谢谢,这就是我的想法。谢谢你的帮助嗨,加布,你找到工作了吗?我也面临同样的问题。
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if([text isEqualToString:@"\n"]){
        float widthLabel = 0.0f;

        UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
            widthLabel = (screenWidth-6)-4-200;
        }else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){
            widthLabel = (screenHeight-24)-4-200;
        }
        textView.frame = CGRectMake(2, 0, widthLabel, textView.frame.size.height+10);

    }
    if(text.length == 0 && [[textView.text substringWithRange:range] isEqualToString:@"\n"]){
        float widthLabel = 0.0f;

        UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        if(UIInterfaceOrientationIsPortrait(interfaceOrientation)){
            widthLabel = (screenWidth-6)-4-200;
        }else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)){
            widthLabel = (screenHeight-24)-4-200;
        }
        textView.frame = CGRectMake(2, 0, widthLabel, textView.frame.size.height-10);

    }
    return YES;
}