Как сделать нестандартный макет для 1 ячейки и второй строки с двумя ячейками в Swift 4 - PullRequest
0 голосов
/ 25 января 2019
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let sizeW = (collectionView.frame.width - 30) / 2

        let des = (self.feeds[indexPath.row].description ?? "").html2String
        let tit = self.feeds[indexPath.row].title ?? ""
        var basicHeight:CGFloat = 80
        if indexPath.item % 3 == 0{
            let heightDescription = self.heightForView(text:des , font: UIFont.systemFont(ofSize: 15.4), width: collectionView.frame.width - 20)
            let heightTitle = self.heightForView(text:tit , font: UIFont.systemFont(ofSize: 15.4), width: collectionView.frame.width - 20)
            basicHeight = basicHeight + heightDescription + heightTitle

            self.heightArray[indexPath.row] = basicHeight
            firstHeight = 0
            return CGSize(width: collectionView.frame.width - 20, height: basicHeight)
        }else{

            let heightDescription = self.heightForView(text:des , font: UIFont.systemFont(ofSize: 15.4), width: sizeW)
            let heightTitle = self.heightForView(text:tit , font: UIFont.systemFont(ofSize: 15.4), width: sizeW)
            basicHeight = basicHeight + heightDescription + heightTitle
            if self.firstHeight > basicHeight
            {
                basicHeight = firstHeight
            }
            else
            {
                self.firstHeight = basicHeight
            }
            if self.firstHeight > 0{
                let heightofFirstCell = self.heightArray[indexPath.row - 1] ?? 0
                if heightofFirstCell < basicHeight
                {
                    self.heightArray[indexPath.row - 1] = basicHeight
                }
            }
            self.heightArray[indexPath.row] = basicHeight
            return CGSize(width: sizeW, height: basicHeight)
        }
    }

Я хочу показать 1 ячейку и 2 ячейки поочередно, но в макете потока он не сохраняет свою позицию Y одинаковой. Как я могу добиться этого с пользовательским макетом. Я совершенно новый для пользовательских макетов. Пожалуйста, помогите

...