且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UICollectionViewFlowLayout 在方向更改时不会失效

更新时间:2023-02-13 18:27:25

一种解决方案是使用 KVO 并监听您的集合视图的父视图框架的变化.调用 -reloadData 将起作用并消除警告.这里有一个潜在的时间问题......

One solution is to use KVO and listen for a change to the frame of the superview for your collection view. Calling -reloadData will work and get rid of the warnings. There is an underlying timing issue here...

// -loadView
[self.view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];

// -dealloc
[self.view removeObserver:self forKeyPath:@"frame"];

// KVO Method
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    [collectionView_ reloadData];
}