【发布时间】:2014-02-26 20:37:23
【问题描述】:
问题
我注意到在通话期间使用UIViewControllerAnimatedTransitioning 呈现UINavigationController(带有根视图控制器,自然已经推送)时出现了一些奇怪的行为。
- 如果在显示导航控制器之后启用通话状态栏,则导航控制器会按预期向下移动其视图。但是当通话结束时,控制器不会将其视图重新向上移动,在状态栏下方留下 20p 的间隙。
- 如果在显示控制器之前启用通话状态栏,控制器根本不考虑状态栏,留下 44p 高导航栏的 4p 从下方窥视40p 状态栏。当通话结束时,控制器会向下移动其视图以适应正常的 20p 状态栏。
*注意:这是在模拟器上测试的,因为启用/禁用通话状态栏很容易,但测试人员在实际手机上观察到了这种现象。
我的(部分)解决方法
如果状态栏的高度异常,我通过在演示期间调整控制器的框架解决了这个问题:
@interface CustomAnimationController : NSObject <UIViewControllerAnimatedTransitioning>
@end
@implementation CustomAnimationController
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *toController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];
CGRect frame = [transitionContext finalFrameForViewController:toController];
if (CGRectEqualToRect(frame, CGRectZero))
{
// In my experience, the final frame is always a zero rect, so this is always hit
UIEdgeInsets insets = UIEdgeInsetsZero;
// My "solution" was to inset the container frame by the difference between the
// actual status bar height and the normal status bar height
insets.top = CGRectGetHeight([UIApplication sharedApplication].statusBarFrame) - 20;
frame = UIEdgeInsetsInsetRect(container.bounds, insets);
}
toController.view.frame = frame;
[container addSubview:toController.view];
// Perform whiz-bang animation here
}
@end
此解决方案确保导航栏位于状态栏下方,但导航控制器在通话结束时仍无法自行返回。所以应用至少可以使用,但是通话结束后导航栏上方有一个难看的 20p 间隙。
有更好的方法吗?
我是否遗漏了一些关键步骤来确保导航控制器自己负责通话状态栏?当使用内置的模态演示样式呈现时,它工作得很好。
在我看来,这有点像 UIKit 错误——毕竟,导航控制器似乎收到了UIApplicationWillChangeStatusBarFrameNotification(参见问题的第二点)。如果其他人遇到此问题并找到了更好的方法,我将不胜感激。
【问题讨论】:
-
你找到解决方法了吗?我的问题是我的应用程序的主屏幕没有导航栏,带有一个有导航栏的滑入式面板。滑入式面板全屏时,通话中的绿色条显示,面板变短,但滑入式面板部分屏幕时,通话进度条消失。因此,当我打开和关闭面板时,面板会变得越来越短。
-
@MusiGenesis 我还没有找到解决办法,但 Apple 确实开始查看我的错误报告。如果他们确认这确实是一个错误,我会在这里发布。
-
@Austin 你找到解决办法了吗?
-
@tikhop 我从未找到解决方案,Apple 也从未回复我的错误报告。它可能在 iOS 8 中被修复;应用程序的设计发生了变化,因此不再需要自定义演示控制器,因此我没有对其进行测试。
-
@Austin,感谢您的回复。所以在 iOS8 中没有任何修复,我遇到了同样的问题,只找到了一个看起来像你的解决方案。
标签: ios uiview ios7 modalviewcontroller ios7-statusbar