【问题标题】:UICollectionViewDelegateFlowLayout methods not called on rotation旋转时未调用 UICollectionViewDelegateFlowLayout 方法
【发布时间】:2015-02-13 19:17:31
【问题描述】:

在我的集合视图布局(UICollectionViewFlowLayout 的子类)内部我定义了:

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {
    return YES;
}

我的期望是,由于旋转是一个边界变化,我的布局将被重新计算。但是,当我在以下位置设置断点时:

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

屏幕旋转时不触发断点。有谁知道为什么?

【问题讨论】:

    标签: ios ios8 uikit uicollectionview


    【解决方案1】:

    collectionView:layout:sizeForItemAtIndexPath: 方法应该在 UI CollectionViewDelegate 类中实现。不在 UICollectionViewLayout 的子类中。 你在哪里实现的?

    PS。没有必要同时使用两者。如果您有自定义 UICollectionViewLayout 类,请改用 layoutAttributesForItemAtIndexPath:

    【讨论】:

    • 我在作为集合视图委托的视图控制器内部实现了collectionView:layout:sizeForItemAtIndexPath:。使用 layoutAttributesForItemAtIndexPath: 对我不起作用。
    • collectionView:layout:sizeForItemAtIndexPath 与 CollectionViewDelegate 在同一类中的实现对我有用..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多