简体   繁体   English

如何在单元格对象中更改IBICction的UICollection View单元格大小

[英]How to change a UICollection View cell size form IBAction in cell object

I am developing a uiCollection view, In which i have 4 cells, on 4th cell i have uiview which hold button and ui textview. 我正在开发一个uiCollection视图,其中我有4个单元格,在第4个单元格上我有uiview,其中包含按钮和ui textview。 once i tap button the textview should reveal and close. 一旦我点击按钮,textview应显示并关闭。

I don't know how to handle this, how to increase particular cell size on inaction in cell object 我不知道如何处理这个问题,如何在细胞对象的不作用中增加特定的细胞大小

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

}

I am struggling to get out of this any help? 我正在努力摆脱这个任何帮助?

You can save indexPath of your particular cell in @property . 您可以保存在您的特定细胞的indexPath @property Create 2 cases in HeightForRowAtIndexPath: with BOOL flag: one for normal size and one for big. HeightForRowAtIndexPath:创建2个案例HeightForRowAtIndexPath:带有BOOL标志:一个用于正常大小,一个用于大。

Then you get button tap, you activate some BOOL flag and reload cell with animation. 然后你点击按钮,激活一些BOOL标志并用动画重新加载单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM