gpt4 book ai didi

ios - 在 iOS 7 下,如何动态隐藏和显示状态栏(无论何时)

转载 作者:IT王子 更新时间:2023-10-29 07:53:26 24 4
gpt4 key购买 nike

假设用户在 View Controller 中并想进入隐藏状态栏的“全屏”类型模式,在 iOS 6 下,这是一个隐藏/显示状态栏的简单方法调用,但无论如何它似乎在 iOS 7 下仍然存在。

我见过这样的解决方案:

- (BOOL)prefersStatusBarHidden {
return YES;
}

但这不允许它在运行时切换。 (它不接受任何参数。)

在我的 info.plist 中,我将 View controller-based status bar appearance 设置为 NO

我已经无计可施了。我如何隐藏它?

最佳答案

swift 4

显示:

(UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow)?.isHidden = false

隐藏:

(UIApplication.shared.value(forKey: "statusBarWindow") as? UIWindow)?.isHidden = true



objective-c

这是一种方法:

在 myViewController.h 中

@interface myViewController : UIViewController {
BOOL shouldHideStatusBar;
}

然后在myViewController.m中

- (void)viewDidLoad {
[super viewDidLoad];
shouldHideStatusBar = YES;
}

- (BOOL)prefersStatusBarHidden {
return shouldHideStatusBar;
}

假设当我触摸屏幕时它现在应该显示状态栏。您需要调用:setNeedsStatusBarAppearanceUpdate 来专门让它工作,然后切换(在本例中为 bool)以显示/隐藏。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
shouldHideStatusBar = (shouldHideStatusBar)? NO: YES;
[self setNeedsStatusBarAppearanceUpdate];
}

setNeedsStatusBarAppearanceUpdate

This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.

prefersStatusBarHidden:

Return Value A Boolean value of YES specifies the status bar should be hidden. Default value is NO.

Discussion If you change the return value for this method, call the setNeedsStatusBarAppearanceUpdate method.

To specify that a child view controller should control preferred status bar hidden/unhidden state, implement the childViewControllerForStatusBarHidden method.


如果您的应用程序也计划与 iOS 6 一起使用,则可能需要查看 this post

关于ios - 在 iOS 7 下,如何动态隐藏和显示状态栏(无论何时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19774968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com