我发现属性layoutAttributesClass的可用性是sdk 10或更高,但是我写了
+ (Class)layoutAttributesClass
{
return [MyCollectionViewLayoutAttributes class];
}
在我的自定义UICollectionViewFlowLayout类中,当在我的手机上测试时(sdk 9),这个函数被调用。那么如何理解sdk的可用性以及何时调用此函数?提前谢谢。
答案 0 :(得分:1)
此属性可从iOS 8或9获得,但不能从iOS 10获得。我认为您可以在iOS 8及更高版本中实现此属性。
答案 1 :(得分:1)
文档具有误导性。自iOS 6.0引入+[UICollectionViewLayout layoutAttributesClass]
时,UICollectionViewLayout
方法已被公开支持。
在Xcode 8中引入了类属性,Xcode 8随iOS 10发布。当时,layoutAttributesClass
被更改为类属性,而不仅仅是类方法。此更改意味着它作为类属性而不是作为类方法导入到Swift中。
在Objective-C中,您仍必须将其作为类方法覆盖。从6.0开始,您编写的代码在iOS的所有版本中都是正确的。
答案 2 :(得分:0)
以下是用于确定SDK中是否有类的代码
if ([UICollectionViewLayoutAttributes class])
{
//Write your code here that you want when the class is available for that sdk.
}