How can I detect UIStatusBar hide and show?












5















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?










share|improve this question





























    5















    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?










    share|improve this question



























      5












      5








      5








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 11 '12 at 5:00







      ch_g

















      asked Oct 11 '12 at 4:15









      ch_gch_g

      283




      283
























          3 Answers
          3






          active

          oldest

          votes


















          5














          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
          }





          share|improve this answer


























          • 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



















          1














          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).






          share|improve this answer































            0














            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.






            share|improve this answer























              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              5














              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
              }





              share|improve this answer


























              • 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
















              5














              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
              }





              share|improve this answer


























              • 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














              5












              5








              5







              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
              }





              share|improve this answer















              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
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              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



















              • 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













              1














              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).






              share|improve this answer




























                1














                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).






                share|improve this answer


























                  1












                  1








                  1







                  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).






                  share|improve this answer













                  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).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 17:26









                  lassejlassej

                  2,98331626




                  2,98331626























                      0














                      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.






                      share|improve this answer




























                        0














                        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.






                        share|improve this answer


























                          0












                          0








                          0







                          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.






                          share|improve this answer













                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 11 '12 at 4:23









                          sumitsumit

                          82




                          82






























                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine