首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 9扩展状态栏错误?

iOS 9扩展状态栏错误?
EN

Stack Overflow用户
提问于 2016-05-16 17:59:00
回答 2查看 317关注 0票数 2

我的应用程序有一个问题,在应用程序的顶部有一个黑色的条,我的整个视图被从顶部向下推了20秒。

下面是一个非常简短的示例项目,它复制了bug:https://github.com/sbiermanlytle/iOS-status-bar-bug/tree/master

复制:

  1. 激活扩展状态栏(在Google地图上启动路由或打开热点)
  2. 启动演示应用程序
  3. 导航到第三视图
  4. 回到第二视图,你会看到顶部的黑色酒吧。

我该怎么摆脱黑酒吧?

下面是示例应用程序的完整说明:

有一系列的3视图控制器,1启动2,UIViewControllerBasedStatusBarAppearance设置为YES,第1和第3视图控制器隐藏状态栏,第2视图显示它。

当您启动第二视图和第三视图时,所有显示都正常,但是当您取消第三视图时,第二视图顶部有一个黑色的栏,不会消失。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-16 19:55:48

看起来像iOS 错误

我不知道如何解决这个问题,但这些方法确实有效:

使用不推荐的API

将Info.plist中的Info.plist条目更改为NO。将这样的代码添加到所有视图控制器(或普通超类,希望您有这样的代码; ):

代码语言:javascript
复制
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:[self prefersStatusBarHidden]];
}

使用丑陋的调整

通过手动更新框架的失败的系统视图时,造成的情况。这可能会或不会破坏测试应用程序之外的一些东西。

UIViewController+TheTweak.h

代码语言:javascript
复制
#import <UIKit/UIKit.h>

@interface UIViewController (TheTweak)

- (void)transitionViewForceLayoutTweak;

@end

UIViewController+TheTweak.m (mind the FIXME注释)中

代码语言:javascript
复制
#import "UIViewController+TheTweak.h"
#import "UIView+TheTweak.h"

@implementation UIViewController (TheTweak)

- (void)transitionViewForceLayoutTweak {
    UIViewController *presenting = [self presentingViewController];
    if (([self presentedViewController] != nil) && ([self presentingViewController] != nil)) {
        if ([self prefersStatusBarHidden]) {
            
            NSUInteger howDeepDownTheStack = 0;
            do {
                ++howDeepDownTheStack;
                presenting = [presenting presentingViewController];
            } while (presenting != nil);
            
            //FIXME: replace with a reliable way to get window throughout whole app, without assuming it is the 'key' one. depends on your app's specifics
            UIWindow *window = [[UIApplication sharedApplication] keyWindow];
            [window forceLayoutTransitionViewsToDepth:howDeepDownTheStack];
        }
    }
}

@end

UIView+TheTweak.h

代码语言:javascript
复制
#import <UIKit/UIKit.h>

@interface UIView (TheTweak)

- (void)forceLayoutTransitionViewsToDepth:(NSUInteger)depth;

@end

UIView+TheTweak.m

代码语言:javascript
复制
#import "UIView+TheTweak.h"

@implementation UIView (TheTweak)

- (void)forceLayoutTransitionViewsToDepth:(NSUInteger)depth {
    if (depth > 0) { //just in case
        for (UIView *childView in [self subviews]) {
            if ([NSStringFromClass([childView class]) isEqualToString:@"UITransitionView"]) {
                childView.frame = self.bounds;
                if (depth > 1) {
                    [childView forceLayoutTransitionViewsToDepth:(depth - 1)];
                }
            }
        }
    }
}

@end

现在,在每个视图控制器(或公共超类中)中:

代码语言:javascript
复制
#import "UIViewController+TheTweak.h"

... // whatever goes here

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self transitionViewForceLayoutTweak];
}

或者你可以把有问题的控制器的背景变成黑色:)

票数 1
EN

Stack Overflow用户

发布于 2016-05-18 14:52:39

最简单的调整

代码语言:javascript
复制
@interface SecondViewController ()

@property (assign, nonatomic) BOOL statusBarHidden;

@end

@implementation SecondViewController

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  self.statusBarHidden = [UIApplication sharedApplication].statusBarHidden; //store current state
}

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  self.statusBarHidden = YES;
  [UIView animateWithDuration:0.2f animations:^{
     [self setNeedsStatusBarAppearanceUpdate];
   }];
}

- (BOOL)prefersStatusBarHidden {
    return self.statusBarHidden;
}
@end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37260258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档