当出现状态栏时,我正在尝试重新加载UICollectionView。我对呼叫中的状态栏(void) application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)newStatusBarFrame使用了Apple Delegate方法。由于UI事件被分派到主线程,因此在此事件的处理程序中,我告诉VC它需要在setNeedsLayout中进行布局更新,然后在从viewDidLayoutSubviews调用的批量更新中显式地重新加载我的集合视图单元格。我想要100%确保每次状态栏出现时都会出现布局周期。我在文档中找不到是不是这样。
根据苹果:https://developer.apple.com/documentation/uikit/uiviewcontroller/1621437-viewwilllayoutsubviews的说法,当视图边界发生变化时,布局周期总是会被调用。在我的示例中,我的视图都被限制在父rootViewController的顶部和底部。因此,从理论上讲,如果它们使用呈现的statusBar响应UIWindow更改,则界限应该改变。
发布于 2018-10-17 07:01:21
在AppDelegate中,我们使用以下命令监听状态栏的更改
- (void) application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)newStatusBarFrame {
// create notification to let
// user know app has presented status bar
// send event in a dispatch_after so the has enough time to go through
// a layout cycle
}在TargetViewController中,侦听从委托发送的自定义通知,并执行以下操作
[[self.view collectionView] invalidateLayout];
[self.view setNeedsLayout];
self.customFlagToCheckInDidLayoutSubviews = YES;
[self.view layoutIfNeeded];最后在viewDidLayoutSubviews中
if (self.customFlagToCheckInDidLayoutSubviews) {
[self.collectionView performBatchUpdates:^{
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
} completion:nil];
}https://stackoverflow.com/questions/52841590
复制相似问题