我不知道如何在我的UICollectionView中调整我的单元格时,当用户正在写入时UITextView变得更大(正如我在下面的代码中所做的那样):
-(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;
}
我想使包含此UITextView的item单元格相对于UITextView变得更大/更小。我无法通过在单元格中使用新高度来更改大小并使用reloadData,因为它会使键盘消失而用户无法再写入。
答案 0 :(得分:1)
我不确定,但我认为您可以尝试使布局无效并强制重绘uicollectionview布局。
看看这个:Resize UICollectionView cells after their data has been set