the behavior of the UICollectionViewFlowLayout is not defined, because the cell width is greater than collectionView width

后端 未结 20 2165
温柔的废话
温柔的废话 2020-12-01 01:53

2015-08-18 16:07:51.523 Example[16070:269647] the behavior of the UICollectionViewFlowLayout is not defined because: 2015-08-18 16:07:51.523
Example

20条回答
  •  北海茫月
    2020-12-01 02:11

    I found that this worked quite well for UICollectionViewController and animated correctly:

    - (void)viewWillTransitionToSize:(CGSize)size
           withTransitionCoordinator:(id)coordinator {
        // Ensure the layout is within the allowed size before animating below, or 
        //  `UICollectionViewFlowLayoutBreakForInvalidSizes` breakpoint will trigger
        //  and the logging will occur.
    
        if ([self.collectionView.collectionViewLayout isKindOfClass:[YourLayoutSubclass class]]) {
            [(YourLayoutSubclass *)self.collectionView.collectionViewLayout updateForWidth:size.width];
        }
    
        // Then, animate alongside the transition, as you would:
    
        [coordinator animateAlongsideTransition:^
            (id  _Nonnull context) {
                [self.collectionView.collectionViewLayout invalidateLayout];
            }
                                     completion:nil];
    
        [super viewWillTransitionToSize:size
              withTransitionCoordinator:coordinator];
    }
    
    ///////////////
    
    @implementation YourLayoutSubclass
    
    - (void)prepareLayout {
        [super prepareLayout];
    
        [self updateForWidth:self.collectionView.bounds.size.width];
    }
    
    - (void)updateForWidth:(CGFloat)width {
        // Update layout as you wish...
    }
    
    @end
    

    ... See inline code comments above for explanation.

提交回复
热议问题