【问题标题】:CollectionView crashes after HOME button pressed on iPads在 iPad 上按下 HOME 按钮后 CollectionView 崩溃
【发布时间】:2017-05-03 12:42:22
【问题描述】:

我有一个 CollectionView,我动态设置了它的单元格的大小。这是问题所在:当我点击“主页”按钮并再次进入游戏时,CollectionView 会出现问题。所有的细胞看起来都很糟糕,它们的大小不正确并且出现在错误的位置。它只发生在 iPad 上并且在 iPhone 上完美运行。 这是我创建表格的代码:

if collectionView == tableCollectionView{

        let cell:TableViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "letter_cell", for: indexPath) as! TableViewCell

        let size = Int(collectionView.frame.size.width) / (lettersCountInRow + 1);
        let j = indexPath.row
        let i = indexPath.section

        let letter = guessLogic!.letters[i * lettersCountInRow + j]
        let imageName = String(describing: letter)

        let vertical_shift = (Int(collectionView.frame.size.height) - size * 2) / 2
        let pad = Double(size) * 0.1;
        let start_x = Int(collectionView.frame.size.width) - size*7 - Int(pad) * lettersCountInRow;


        cell.letterImage.image = UIImage(named: imageName)
        cell.frame = CGRect(x:start_x + j * Int(pad) + j * size, y: i * size + vertical_shift + Int(pad), width: size, height: size)

        return cell

    }

在 iPad Air-2 上测试

这就是表格的外观: Normal look

这是我按下 HOME 并返回游戏后的样子: Wrong bullsh*t look

【问题讨论】:

  • 您能否提供代码如何设置单元格的大小?
  • 请添加一些截图。
  • 请查看问题中的新信息

标签: ios swift3 uicollectionview


【解决方案1】:

您是否在 viewdidload() 中设置了单元格的大小? 在这种情况下,尝试在 viewdidappear() 中执行它并查看。

【讨论】:

  • 不,我在这个方法中调整单元格的大小 ** func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell **
【解决方案2】:

嗯,我找到了解决方案。这是因为方向。我禁用了横向,一切都开始正常工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多