美文网首页iOS 开发每天分享优质文章iOS Developer
iOS双击Home键进入switcher任务管理切屏退出进入闪屏

iOS双击Home键进入switcher任务管理切屏退出进入闪屏

作者: Fiona_L | 来源:发表于2017-03-15 14:36 被阅读562次

前几天偶然发现了一个bug是,打开程序后双击home键,进入任务管理器时,程序会闪动一下,本来以为是接收了在applicationWillResignActive中注册的通知,执行了页面刷新,但是打断点发现没有走到的时候就已经有闪屏现象了。
后来查了一下发现很多人跳转其他app也有类似的问题,最终知道是因为隐藏返回按钮的文字引起。

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) 
                              forBarMetrics:UIBarMetricsDefault];

UIOffsetMake(NSIntegerMin, NSIntegerMin) 表示将文字向负无穷方向偏移。
解决方案有三。如下:

  1. 将文字颜色设置为透明
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor clearColor]} 
                              forState:UIControlStateNormal];
  1. 将文字设置为空
  - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
      viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
      [super pushViewController:viewController animated:animated];
}

但是实际上,设置偏移量并不会引起闪屏,将偏移量改小就可以避免这个问题,但是至于为什么无穷值会导致闪屏,原因还未知。。。

相关文章

网友评论

    本文标题:iOS双击Home键进入switcher任务管理切屏退出进入闪屏

    本文链接:https://www.haomeiwen.com/subject/rqdlnttx.html