我的应用程序有一个问题,在应用程序的顶部有一个黑色的条,我的整个视图被从顶部向下推了20秒。
下面是一个非常简短的示例项目,它复制了bug:https://github.com/sbiermanlytle/iOS-status-bar-bug/tree/master
复制:
我该怎么摆脱黑酒吧?
下面是示例应用程序的完整说明:
有一系列的3视图控制器,1启动2,UIViewControllerBasedStatusBarAppearance设置为YES,第1和第3视图控制器隐藏状态栏,第2视图显示它。
当您启动第二视图和第三视图时,所有显示都正常,但是当您取消第三视图时,第二视图顶部有一个黑色的栏,不会消失。
发布于 2016-05-16 19:55:48
看起来像iOS 错误。
我不知道如何解决这个问题,但这些方法确实有效:
使用不推荐的API
将Info.plist中的Info.plist条目更改为NO。将这样的代码添加到所有视图控制器(或普通超类,希望您有这样的代码; ):
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarHidden:[self prefersStatusBarHidden]];
}使用丑陋的调整
通过手动更新框架的失败的系统视图时,造成的情况。这可能会或不会破坏测试应用程序之外的一些东西。
在UIViewController+TheTweak.h中
#import <UIKit/UIKit.h>
@interface UIViewController (TheTweak)
- (void)transitionViewForceLayoutTweak;
@end在UIViewController+TheTweak.m (mind the FIXME注释)中
#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中
#import <UIKit/UIKit.h>
@interface UIView (TheTweak)
- (void)forceLayoutTransitionViewsToDepth:(NSUInteger)depth;
@end在UIView+TheTweak.m中
#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现在,在每个视图控制器(或公共超类中)中:
#import "UIViewController+TheTweak.h"
... // whatever goes here
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self transitionViewForceLayoutTweak];
}或者你可以把有问题的控制器的背景变成黑色:)
发布于 2016-05-18 14:52:39
最简单的调整
@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;
}
@endhttps://stackoverflow.com/questions/37260258
复制相似问题