我正在开发一个uiCollection视图,其中我有4个单元格,在第4个单元格上我有uiview,其中包含按钮和ui textview。一旦我点击按钮,文本视图就会显示并关闭。
我不知道如何处理这个问题,如何在单元格对象的不作为中增加特定的单元格大小
UICollectionview.M
#pragma mark - UICollectionView DataSource & Delegate methods
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 4;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section==2) {
UICollectionViewCell * cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier2 forIndexPath:indexPath];
return cell;
}
else if(indexPath.section==1){
UICollectionViewCell * cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier1 forIndexPath:indexPath];
return cell;
}
else if(indexPath.section==0){
UICollectionViewCell * cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
return cell;
}
else{
infoCell * cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier3 forIndexPath:indexPath];
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 3) {
return CGSizeMake(self.width, self.height);
}
else{
return CGSizeMake(309, 300);
}
}
@end
cell object
cellobject.h
@interface InfoCell : UICollectionViewCell
{
BOOL toggleIsOn;
}
@property (weak, nonatomic) IBOutlet UIView *infoView;
@property (weak, nonatomic) IBOutlet UIButton *dropDownButton;
@property (weak, nonatomic) IBOutlet UITextView *infoDescrip;
@end
cell object.m
-(IBAction)revealDescription:(id)sender{
if (toggleIsOn)
{
self.infoDescrip.hidden= YES;
self.infoView.frame=CGRectMake(0, 0, 309,44);
}
else
{
self.infoDescrip.hidden= NO;
NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:14]};
CGRect rect = [self.infoDescrip.text boundingRectWithSize:CGSizeMake(300, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes context:nil];
self.infoDescrip.frame= CGRectMake(0, 46, 300, rect.size.height);
self.infoView.frame=CGRectMake(0, 0, 309, rect.size.height+50);
}
toggleIsOn = !toggleIsOn;
[self.dropDownButton setImage:[UIImage imageNamed:toggleIsOn ? @"arrow_down_blue" :@"arrow_right_blue"] forState:UIControlStateNormal];
}
我正在努力摆脱这个任何帮助吗?
答案 0 :(得分:0)
您可以在@property
中保存特定单元格的indexPath。使用BOOL标志在HeightForRowAtIndexPath:
中创建2个案例:一个用于正常大小,一个用于大。
然后你点击按钮,激活一些BOOL标志并用动画重新加载单元格。