Swift UICollectionView iPad流程布局不起作用

时间:2018-05-24 06:58:01

标签: ios swift ipad layout uicollectionview

目前在iPad上使用集合视图遇到Flow布局的一些问题。我目前正在开发一个应用程序,它以流布局显示帖子,使其看起来美观而时尚。但是,在所有设备上测试应用程序时,我注意到显示屏发生了变化:

  • iPad 5th Generation
  • iPad Air
  • iPad Air 2
  • iPad Pro(9,7英寸)

但剩余的iPad,它显示正常。这里似乎有什么问题?我目前正在使用此代码在CollectionView中设置我的布局:

 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        switch UIDevice().screenType {
        case .iPhoneX:
            return CGSize(width: 180.0, height: 180.0)
            break
        case .iPhone5:
            return CGSize(width: 152.0, height: 152.0)
            break
        case .iPhone6:
            return CGSize(width: 180.0, height: 180.0)
            break
        case .iPhone6Plus:
            return CGSize(width: 200.0, height: 200.0)
            break
        case .iPad:
            return CGSize(width: 400.0, height: 400.0)
            break
        case .iPadTwo:
            return CGSize(width: 400.0, height: 400.0)
            break
        case .iPadThree:
            return CGSize(width: 400.0, height: 400.0)
            break
        default:
            return CGSize(width: 200.0, height: 200.0)
            break
        }
    }

' iPad Two'和#3; iPad Three'只是我试图创建的一些枚举,试图确定iPad类型,如果我得到一个输出打印一些文本(但它只是下降到默认值),无论iPad。

这是我的屏幕尺寸:

 switch UIScreen.main.nativeBounds.height {
        case 960:
            return .iPhone4
        case 1136:
            return .iPhone5
        case 1334:
            return .iPhone6
        case 2208:
            return .iPhone6Plus
        case 1024:
            return .iPad
        case 1366:
            return .iPadTwo
        case 834:
            return .iPadThree
        case 2436:
            return .iPhoneX
            break
        default:
            return .unknown
        }

以下是我所问题的直观表示,在所列设备上发生,但其余部分则没有:

它应该是什么样的:

This is how it's supposed to look like.

列出的设备上看起来如何:

enter image description here

如果有人可以帮我解决这个问题,我真的很感激帮助,因为我似乎无法找到一个正常工作的解决方案。

0 个答案:

没有答案