相关疑难解决方法(0)

动态UICollectionViewCell宽度相对于帧宽和宽高比

这是来自UICollectionViewCell动态调整4.4和5.5英寸的后续问题

虽然这个解决方案很棒,但我想根据设备的宽度,宽高比和我必须显示的总项目数量在UIVIewController中生成动态数量的项目单元格(kCellsPerRow).我只是无法弄清楚如何计算正确数量的kCellsPerRow,以便一旦达到宽高比限制它们就不会过于调整大小.

这是我到目前为止所拥有的:

var kCellsPerRow = ceil(global.TotalAmount)                //Total Amount of Cells
var windowWidth = layout.collectionView!.frame.width        // Device's Window Width 
var dynamicWidth = windowWidth / CGFloat(kCellsPerRow)    // Current Width of Each Cell
var dynamicHeight = windowWidth / CGFloat(kCellsPerRow)    // Current Height of Each Cell
var limit = (Double(dynamicWidth) / Double(windowWidth))*(9/2) < (2/9)    // Constraint/Threshold

if ( limit ) {
    var newkCellsPerRow = CGFloat(kCellsPerRow * (2/9))    // Attempt
    newkCellsPerRow = 9  // Fixed Size of 9 but what if we …
Run Code Online (Sandbox Code Playgroud)

dynamic uicollectionview uicollectionviewcell uicollectionviewlayout swift

0
推荐指数
1
解决办法
2071
查看次数