【发布时间】:2018-11-03 07:13:33
【问题描述】:
目前在 iPad 上使用集合视图的 Flow 布局存在一些问题。我目前正在开发一个以流式布局显示帖子的应用程序,使其看起来既漂亮又时尚。但是,当在所有设备上测试应用程序时,我注意到显示发生了变化:
- 第五代 iPad
- iPad 空气
- iPad 空气 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' 和 '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
}
这是我的问题的直观表示,出现在列出的设备上,但没有出现在其他设备上:
它应该是什么样子:
在所列设备上的外观:
如果有人可以帮助我解决此问题,我将非常感谢您的帮助,因为我似乎无法找到一个正常工作的解决方案。
【问题讨论】:
-
请参考此链接:stackoverflow.com/questions/49937074/… 并尝试这样做。
标签: ios swift ipad layout uicollectionview