如何在单元格对象中从IBAction更改UICollection View单元格大小



我正在开发一个uiCollection视图,其中我有4个单元格,在第4个单元格上我有按住按钮的uiview和uitextview。一旦我点击按钮,文本视图就会显示并关闭。

我不知道如何处理这个问题,如何在单元格对象中增加不作为的特定单元格大小

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];
}

我正在努力摆脱困境,有什么帮助吗?

您可以将特定单元格的indexPath保存在@property中。在带有BOOL标志的HeightForRowAtIndexPath:中创建两个案例:一个用于正常大小,一个用于大。

然后点击按钮,激活一些BOOL标志并用动画重新加载单元格。

最新更新