How can I detect UIStatusBar hide and show?
I'm trying to detect hidden and show of iPhone's UIStatusBar but failed. Are there any solution can help me, like KVO or something else?
iphone ios uiapplication
add a comment |
I'm trying to detect hidden and show of iPhone's UIStatusBar but failed. Are there any solution can help me, like KVO or something else?
iphone ios uiapplication
add a comment |
I'm trying to detect hidden and show of iPhone's UIStatusBar but failed. Are there any solution can help me, like KVO or something else?
iphone ios uiapplication
I'm trying to detect hidden and show of iPhone's UIStatusBar but failed. Are there any solution can help me, like KVO or something else?
iphone ios uiapplication
iphone ios uiapplication
edited Oct 11 '12 at 5:00
ch_g
asked Oct 11 '12 at 4:15
ch_gch_g
283
283
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can observe the statusBarHidden
property of the shared UIApplication
instance.
Simple example:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// Do something here...
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
[[UIApplication sharedApplication] setStatusBarHidden:YES]; // Will notify the observer about the change
}
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
|
show 1 more comment
From iOS 11 and up you can subclass the UIView of the view controller and override safeAreaInsetsDidChange
:
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
// adapt your view
}
Your view must share the top rect with the status bar for this to work. (But if it doesn't, you probably wouldn't need to detect changes anyway).
add a comment |
In UIApplication class there is a property statusBarHidden...this tell status bar hidden or not...if it return YES mean status bar is hidden...try this.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12832126%2fhow-can-i-detect-uistatusbar-hide-and-show%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can observe the statusBarHidden
property of the shared UIApplication
instance.
Simple example:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// Do something here...
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
[[UIApplication sharedApplication] setStatusBarHidden:YES]; // Will notify the observer about the change
}
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
|
show 1 more comment
You can observe the statusBarHidden
property of the shared UIApplication
instance.
Simple example:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// Do something here...
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
[[UIApplication sharedApplication] setStatusBarHidden:YES]; // Will notify the observer about the change
}
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
|
show 1 more comment
You can observe the statusBarHidden
property of the shared UIApplication
instance.
Simple example:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// Do something here...
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
[[UIApplication sharedApplication] setStatusBarHidden:YES]; // Will notify the observer about the change
}
You can observe the statusBarHidden
property of the shared UIApplication
instance.
Simple example:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// Do something here...
}
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] addObserver:self forKeyPath:@"statusBarHidden" options:NSKeyValueObservingOptionNew context:NULL];
[[UIApplication sharedApplication] setStatusBarHidden:YES]; // Will notify the observer about the change
}
edited Oct 11 '12 at 4:29
answered Oct 11 '12 at 4:23
JustSidJustSid
23.1k56487
23.1k56487
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
|
show 1 more comment
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
In fact, I encounter this problem when I use MPMoviePlayerController. I set moviePlayer fullscreen and want do something when MPCenteringNavigationBar showed
– ch_g
Oct 11 '12 at 4:43
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
I tried this method but it still not work
– ch_g
Oct 11 '12 at 4:50
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
"-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context" this function is called just twice.
– ch_g
Oct 11 '12 at 4:58
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
Is there a way to make this implementation work for [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide] ?
– Shawn
Feb 9 '16 at 19:32
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
This does not work. The UIApplication does not notify observers about changes to statusBarHidden.
– Perrin Larson
Dec 23 '16 at 21:29
|
show 1 more comment
From iOS 11 and up you can subclass the UIView of the view controller and override safeAreaInsetsDidChange
:
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
// adapt your view
}
Your view must share the top rect with the status bar for this to work. (But if it doesn't, you probably wouldn't need to detect changes anyway).
add a comment |
From iOS 11 and up you can subclass the UIView of the view controller and override safeAreaInsetsDidChange
:
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
// adapt your view
}
Your view must share the top rect with the status bar for this to work. (But if it doesn't, you probably wouldn't need to detect changes anyway).
add a comment |
From iOS 11 and up you can subclass the UIView of the view controller and override safeAreaInsetsDidChange
:
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
// adapt your view
}
Your view must share the top rect with the status bar for this to work. (But if it doesn't, you probably wouldn't need to detect changes anyway).
From iOS 11 and up you can subclass the UIView of the view controller and override safeAreaInsetsDidChange
:
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()
// adapt your view
}
Your view must share the top rect with the status bar for this to work. (But if it doesn't, you probably wouldn't need to detect changes anyway).
answered Nov 14 '18 at 17:26
lassejlassej
2,98331626
2,98331626
add a comment |
add a comment |
In UIApplication class there is a property statusBarHidden...this tell status bar hidden or not...if it return YES mean status bar is hidden...try this.
add a comment |
In UIApplication class there is a property statusBarHidden...this tell status bar hidden or not...if it return YES mean status bar is hidden...try this.
add a comment |
In UIApplication class there is a property statusBarHidden...this tell status bar hidden or not...if it return YES mean status bar is hidden...try this.
In UIApplication class there is a property statusBarHidden...this tell status bar hidden or not...if it return YES mean status bar is hidden...try this.
answered Oct 11 '12 at 4:23
sumitsumit
82
82
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f12832126%2fhow-can-i-detect-uistatusbar-hide-and-show%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown