【发布时间】:2014-04-10 17:48:59
【问题描述】:
我不知道如何调整我的 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 的项目单元格相对于 UITextView 变得更大/更小。我无法通过调整单元格的新高度并使用 reloadData 来更改大小,因为它会使键盘消失并且用户无法再书写。
【问题讨论】:
-
嗨,盖比,你找到解决办法了吗?我也面临同样的问题。
标签: ios uitextview uicollectionview