在使用STPop弹出Controller的时候遇到了这种情况:
查看调试器:
离顶部有44个像素 , 一看这种情况以为是需要设置弹出的controller的一些属性 比如:
//去除顶部的空白间隙
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.modalPresentationCapturesStatusBarAppearance = NO;
self.automaticallyAdjustsScrollViewInsets=NO;
但是发现没用~
这样的情况接下来直接导致后面弹出的controller受到影响:
最后发现是配置STPopcontroller 的一个属性造成的:
STPopupController *pop = [[STPopupController alloc] initWithRootViewController:controller];
// 如果是全屏尺寸 需要设置为true才能消除顶部的空白
pop.navigationBarHidden= true;
我查看STPopController 的源码 发现于此相关的内容:
- (void)setNavigationBarHidden:(BOOL)navigationBarHidden animated:(BOOL)animated
{
_navigationBarHidden = navigationBarHidden;
_navigationBar.alpha = navigationBarHidden ? 1 : 0;
if (!animated) {
[self layoutContainerView];
_navigationBar.hidden = navigationBarHidden;
return;
}
if (!navigationBarHidden) {
_navigationBar.hidden = navigationBarHidden;
}
[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:1 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self->_navigationBar.alpha = navigationBarHidden ? 0 : 1;
[self layoutContainerView];
} completion:^(BOOL finished) {
self->_navigationBar.hidden = navigationBarHidden;
}];
}
//这里主要实现 frame 的逻辑
- (void)layoutContainerView
{
CGAffineTransform lastTransform = _containerView.transform;
_containerView.transform = CGAffineTransformIdentity;
_backgroundView.frame = _containerViewController.view.bounds;
CGFloat preferredNavigationBarHeight = [self preferredNavigationBarHeight];
//就是这里造成的空白 navigationBarHeight的高度直接由navigationBarHidden决定
//而preferredNavigationBarHeight会去获取navBar相关的高度可以看具体的实现
CGFloat navigationBarHeight = _navigationBarHidden ? 0 : preferredNavigationBarHeight;
CGSize contentSizeOfTopView = [self contentSizeOfTopView];
CGFloat containerViewWidth = contentSizeOfTopView.width;
CGFloat containerViewHeight = contentSizeOfTopView.height + navigationBarHeight;
CGFloat containerViewY = (_containerViewController.view.bounds.size.height - containerViewHeight) / 2;
if (self.style == STPopupStyleBottomSheet) {
containerViewHeight += _safeAreaInsets.bottom;
containerViewY = _containerViewController.view.bounds.size.height - containerViewHeight;
containerViewHeight += STPopupBottomSheetExtraHeight;
}
_containerView.frame = CGRectMake((_containerViewController.view.bounds.size.width - containerViewWidth) / 2,
containerViewY, containerViewWidth, containerViewHeight);
_navigationBar.frame = CGRectMake(0, 0, containerViewWidth, preferredNavigationBarHeight);
_contentView.frame = CGRectMake(0, navigationBarHeight, contentSizeOfTopView.width, contentSizeOfTopView.height);
UIViewController *topViewController = self.topViewController;
topViewController.view.frame = _contentView.bounds;
_containerView.transform = lastTransform;
}
重新配置
pop.navigationBarHidden = true;
就可以了~