簡體   English   中英

在集合視圖的cellForItemAtIndexPath方法中更改框架

[英]Changing Frame in Collection View's cellForItemAtIndexPath Method

我是IOS的新手。

我已使用收藏夾視圖。 我在其中使用原型單元格。 我沒有在應用程序中使用自動版式。

我需要更改按鈕的框架並在cellForItemAtIndexPath查看。 但是,當我第一次滾動到下一個單元格時,它並沒有第一次反映出來。 我只能看到沒有任何按鈕或視圖的空白。 我檢查了所有框架是否正確更新。 我仍然看不到任何東西。

雖然如果我再次去上一個電話然后再回來,它將可以正常顯示。

請在下面找到cellForItemAtIndexPath代碼

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{    
     Feed *feed;
    NSMutableAttributedString * string;

    feed = [arrTop objectAtIndex:indexPath.row];

    ShuffleCell *myCell = [collectionView
                         dequeueReusableCellWithReuseIdentifier:@"ShuffleCell"
                         forIndexPath:indexPath];

    myCell.index = indexPath;


    myCell.delegate = self;


   // Below frame changes are not working


        myCell.vwBack.frame = collect.frame;
        myCell.imgShare.frame = CGRectMake(myCell.imgShare.frame.origin.x, myCell.imgShare.frame.origin.y, self.view.frame.size.width,self.view.frame.size.width );
        myCell.lblText.center = CGPointMake(myCell.imgShare.frame.size.width / 2, myCell.imgShare.frame.size.height / 2);
        myCell.lblText.frame = CGRectMake(20
                                          , myCell.imgShare.frame.origin.y + 20, self.view.frame.size.width - 20,self.view.frame.size.width -20);

        int totHeight = (collect.frame.size.height - self.view.frame.size.width);
        myCell.vwBtn.frame = CGRectMake(myCell.vwBtn.frame.origin.x, collect.frame.size.height -totHeight, myCell.vwBtn.frame.size.width, totHeight);
        [myCell.vwBtn setFrame:CGRectMake(myCell.vwBtn.frame.origin.x, collect.frame.size.height -totHeight, myCell.vwBtn.frame.size.width, totHeight)];
        myCell.btnFavoriteBack.frame = CGRectMake(myCell.btnFavoriteBack.frame.origin.x, 0, myCell.btnFavoriteBack.frame.size.width, totHeight/3);
        [myCell.btnFavoriteBack setFrame:CGRectMake(myCell.btnFavoriteBack.frame.origin.x, 0, myCell.btnFavoriteBack.frame.size.width, totHeight/3)];
        myCell.btnShare.frame = CGRectMake(myCell.btnShare.frame.origin.x, (totHeight/3), myCell.btnShare.frame.size.width, totHeight/3);
        myCell.btnReport.frame = CGRectMake(myCell.btnReport.frame.origin.x, (totHeight/3)*2, myCell.btnReport.frame.size.width, totHeight/3);
        myCell.vwLikeBtn.frame = CGRectMake(self.view.frame.size.width - 82, (totHeight/3 - 32)/2, 82,32);

        NSLog(@"Y :- %f",myCell.vwBtn.frame.size.height);





    return myCell;

我還附有相同的屏幕截圖。

感謝幫助。

添加此行應解決此問題。 讓單元的子視圖將其框架轉換為約束。

cell.label.translatesAutoresizingMaskIntoConstraints = YES;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM