iOS 상태 표시 줄을 숨기는 방법
내 iOS 비디오 앱 상태 표시 줄이 일부보기 컨트롤러에 숨겨져 있습니다. 다음 코드를 사용 하여이 작업을 수행했습니다.
[[UIApplication sharedApplication] setStatusBarHidden:YES];
iOS 5 및 iOS 6에서는 작동하지만 iOS 7에서는 작동하지 않습니다.
특정 뷰 컨트롤러 에서이 작업을 시도했지만
예 :
-(BOOL)prefersStatusBarHidden { return YES; }
잘 작동하지만 부모보기 컨트롤러에서 상태 표시 줄을 다시 표시 할 수 없습니다.
이 값을 plist에 추가해야합니다. " 제어기 기반 상태 표시 줄보기 "및 " NO "로 설정하십시오 .
Info.plist에 다음을 추가하십시오.
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
viewdidload에 다음 줄 추가
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];
새로운 방법을 추가
- (BOOL)prefersStatusBarHidden {
return YES;
}
info.plist 파일도 변경합니다. 컨트롤러 기반 상태 표시 줄보기 "= NO
나를위한 작품
Plist에서 다음 특성을 추가하십시오.
Status bar is initially hidden = YES
View controller-based status bar appearance = NO
이제 상태 표시 줄이 숨겨집니다.
이 간단한 방법을 사용해보십시오.
목표 -C :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated]
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
}
빠른:
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}
override func viewWillDisappear(animated: Bool)
{
super.viewWillDisappear(animated)
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
}
나는 다음을했고 그것이 작동하는 것처럼 보입니다 (iOS 8에서도).
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- UIApplication.setStatusBarX는 iOS9부터 사용되지 않습니다.
- info.plist에 UIViewControllerBasedStatusBarAppearance = NO를 사용하는 것이 더 이상 사용되지 않습니다.
- 모든 뷰 컨트롤러에서 preferredStatusBarX를 사용해야합니다
그러나 UINavigationController가 있으면 더 흥미로워집니다.
- navigationBarHidden = true 인 경우 자식이 상태 표시 줄 아래에 내용을 표시하므로 자식 UIViewController의 preferredStatusBarX가 호출됩니다.
- navigationBarHidden = false이면 UINavigationController의 preferredStatusBarX가 호출되고 결국 상태 표시 줄 아래에 컨텐츠가 표시됩니다.
- UINavigationController의 기본 preferenceStatusBarStyle은 UINav.navigationBar.barStyle의 값을 사용합니다. .Default = 검정 상태 표시 줄 내용, .Black = 흰색 상태 표시 줄 내용.
- So if you're setting barTintColor to some custom colour (which you likely are), you also need to set barStyle to .Black to get white status bar content. I'd set barStyle to black before setting barTintColor, in case barStyle overrides the barTintColor.
- An alternative is that you can subclass UINavigationController rather than mucking around with bar style.
- HOWEVER, if you subclass UINavigationController, you get no control over the status bar if navigationBarHidden = true. Somehow UIKit goes direct to the child UIViewController without asking the UINavigationController in this situation. I would have thought it should be the UINavigationController's responsibility to ask the child >shrugs<.
- And modally displayed UIViewController's only get a say in the status bar if modalPresentationStyle = .FullScreen.
- If you've got a custom presentation style modal view controller and you really want it to control the status bar, you can set modalPresentationCapturesStatusBarAppearance = true.
To hide status bar in iOS7 you need 2 lines of code
in application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions write
[[UIApplication sharedApplication] setStatusBarHidden:YES];
in info.plist add this
View-Controller Based Status Bar Appearance = NO
For better understanding add some photos with comments:
App before any changes
Found in your Project Navigator
folder named Supporting Files
and click on *.plist file
After you will get different setting of your app showed. You need to add 2 keys UIStatusBarHidden
and UIViewControllerBasedStatusBarAppearance
. You can do this simply clicking on + button
After pressing + you can choose one of the key - just start to type.
Correct version:
And finally application after applying this changes:
Also, you can find alternative solution here
In iOS10 all I needed to do is override the prefersStatusBarHidden
var in my RootViewController
(Swift):
override var prefersStatusBarHidden: Bool {
return true
}
Try that;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
To hide your status bar in iOS7:
Open Your plist-file, then add a add a row called "View controller-based status bar appearance" and set its value to NO
.
Here is the Swift version (pre iOS9):
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.None)
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)
}
This also works (iOS7+):
override func prefersStatusBarHidden() -> Bool {
return true
}
You also need to call:
setNeedsStatusBarAppearanceUpdate()
in say viewDidLoad()
.
Note that if you use a SplitView controller, or some other container
view controller, you also need to have it return your class when its sent childViewControllerForStatusBarHidden
. One way to do this is have a public weak var for say statusController
, and return it in this overridden method.
You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".
Steps for hide status bar in iOS
1. open AppDelegate.m file, add application.statusBarHidden in didFinishLaunchingWithOptions method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
application.statusBarHidden = YES;
return YES;
}
- open info.plist and set
View controller-based status bar appearance
set NO
iOS 9 onwards :
As statusBarHidden
method was Deprecated from iOS9 you need to add two values in plist as below :
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
or by User Interface Please refre below image :
As statusBarHidden
is Deprecated from iOS9 :
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;
FIXED SOLUTION FOR SWIFT 3+ (iOS 9, 10)
1- In info.plist set below property
2- Paste below code to Root controller , To
private var isStatusBarHidden = true {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}
override var prefersStatusBarHidden: Bool {
return isStatusBarHidden
}
You can call isStatusBarHidden = true
and isStatusBarHidden = false
where you want to hide/show
status bar
Swift 5
Use following steps to hide iOS Status Bar:
- Open on Info.plist.
- Add new key View controller-based status bar appearance and value set to NO.
- Add new key Status bar is initially hidden and value set to YES.
- Re-compile project.
- Status bar should hidden on iOS phone now.
Final Settings Screenshot:
이것은 Xcode 10.2에서 작동합니다.
보낸 사람 UIKit
> UIApplication.h
:
// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden;
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_AVAILABLE_IOS(3_2);
따라서 View controller-based status bar appearance
NO로 설정해야합니다
Susitha의 질문에 대답하려면 setNeedsStatusBarAppearanceUpdate를 사용하십시오 . 그러면 원하는 statusbar 상태로 refresh하기 위해 prefersStatusBarHidden을 호출합니다. 이 시도:
@property (nonatomic, getter=isHideStatusBar) BOOL hideStatusBar; // Give this a default value early
- (BOOL)prefersStatusBarHidden {
return self.isHideStatusBar;
}
- (void)someMethod {
// triggered by an event or user action
[self setHideStatusBar:YES];
[self setNeedsStatusBarAppearanceUpdate];
}
상태 표시 줄을 다시 보려면 hideStatusBar 속성 (또는 호출 한 항목)을 NO로 설정하십시오. 에 대한 다른 호출을 통해 preferStatusBarHidden을 간접적으로 호출
[self setNeedsStatusBarAppearanceUpdate]
스위프트 3 업데이트 :
다음 정보로 Info.plist를 업데이트하십시오.
View controller-based status bar appearance: NO
그런 다음 ViewController 또는 다른 곳에서 :
UIApplication.shared.isStatusBarHidden = true
참고 URL : https://stackoverflow.com/questions/18979837/how-to-hide-ios-status-bar
'Programing' 카테고리의 다른 글
tmux set -g 마우스 모드가 작동하지 않습니다 (0) | 2020.04.27 |
---|---|
SQL Server 구성 관리자를 찾을 수 없습니다 (0) | 2020.04.27 |
SSL에서 사용하기 위해 Java 키 저장소에서 기존 X.509 인증서 및 개인 키를 가져 오는 방법은 무엇입니까? (0) | 2020.04.27 |
Swift에서 탐색 막대 색상 변경 (0) | 2020.04.27 |
아이폰 : 현재 밀리 초를 얻는 방법? (0) | 2020.04.27 |