• 起风了001
    2019-05-15
    回答一下为什么不用遵守UICollectionViewDelegateFlowLayout就可以直接调用它的协议方法这个问题.

    我们可以看到UICollectionViewDelegateFlowLayout是继承自UICollectionViewDelegate协议, 而UICollectionView里面只有一个delegate: UICollectionViewDelegate?类型的delegate属性, 所以实际上并不需要直接声明实现UICollectionViewDelegateFlowLayout, 只需要声明实现UICollectionViewDelegate即可. 不过我用swift测试了一下, 需要声明为UICollectionViewDelegateFlowLayout, 否则虽然能通过编译但是并没有什么效果.

    建议老师把每一课的代码都单独放出来, 这样我们分析的时候也快速一些, 现在要看代码只能回头一点点看看视频了.
    展开
     1
     2
  • Bojack
    2019-09-26
    如果cell高度不同,该如何处理呢

    作者回复: 在课程中也实现了不同高度和宽度的简单样式。实现UICollectionViewDelegateFlowLayout中的- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath,根据indexpath返回对应的大小即可。如果使用自定义的layout,也可以在UICollectionViewLayout (UISubclassingHooks)中实现对应的函数,返回自定义的item attributes。

    
    
  • zzz
    2019-05-29
    2楼说的特别好,补充一点 在创建collectionView的时候,需要设置collectionViewLayout为对应的UICollectionViewFlowLayout
    
    
  • JopYin
    2019-05-14
    为什么不用遵守UICollectionViewDelegateFlowLayout就可以直接调用它的协议方法- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

    作者回复: UICollectionViewDelegateFlowLayout是继承自UICollectionViewDelegate,当我们设置了collectionView 的layout为UICollectionViewFlowLayout,设置collectionView的delegate就可以了哈

    
    
我们在线,来聊聊吧