相关疑难解决方法(0)

如何使用UICollectionViewTransitionLayout插入自定义UICollectionViewLayoutAttributes属性

我有两个UICollectionViewLayout使用自定义UICollectionViewLayoutAttributes子类的自定义对象.这些自定义属性添加一个属性tintAlpha,该属性控制附加到每个集合视图单元格的色调覆盖视图的不透明度.

我现在想要使用UICollectionViewTransitionLayout子类在这两个布局之间进行转换.如何配置转换布局子类以tintAlpha在我的自定义布局属性上插入自定义属性?

我可以这样做:

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
     CustomLayoutAttributes *attr = [super layoutAttributesForItemAtIndexPath:indexPath];

     CustomLayoutAttributes *fromAttr = (CustomLayoutAttributes *)[self.currentLayout layoutAttributesForItemAtIndexPath:indexPath];
     CustomLayoutAttributes *toAttr = (CustomLayoutAttributes *)[self.nextLayout layoutAttributesForItemAtIndexPath:indexPath];

     CGFloat t = self.transitionProgress;
     attr.tintAlpha = (1.0f - t) * fromAttr.tintAlpha + t * toAttr.tintAlpha;

     return attr;
}
Run Code Online (Sandbox Code Playgroud)

但是,这将忽略应用于当前或下一个布局中的initialLayoutAttributesForAppearingItemAtIndexPath:&属性的任何更改finalLayoutAttributesForDisappearingItemAtIndexPath:,因此实际上并不正确.据我所知,默认实现UICollectionViewTransitionLayout确定适当的from/to属性并缓存它们,或者在prepareLayout或中layoutAttributesForItemAtIndexPath:.拥有一些公共API UICollectionViewTransitionLayout以允许我们从属性对象访问这些对象是非常有用的,就好像我尝试实现我自己的逻辑关于是否使用初始/最终属性与标准属性一样必须是默认实现中的一些差异.

在布局转换期间是否有更好的方法来插入这些自定义属性?


更新:

我刚刚遇到这个场景的另一个问题.在上面的代码中,取得当fromAttrtoAttr从当前/下一个布局直接地说,collectionViewnil用于当前布局(超过过渡至少第一次运行循环).如果布局完全取决于集合视图的边界 - 例如考虑一个简单的封面流布局 - …

transitions ios uicollectionviewlayout

11
推荐指数
1
解决办法
2930
查看次数

标签 统计

ios ×1

transitions ×1

uicollectionviewlayout ×1