2
votes

Note: in iOS 8, Status bar hides itself automatically in landscape and comes back in portrait(iPhone only).

To show videos in my app, I am using XCDYouTubeKit, which is a light wrapper on MPMoviePlayerViewController.

I had to set "View controller-based status bar appearance" in info.plist file to "NO" in my app due to some functionality. The app works fine till you don't use XCDYouTubeKit(MPMoviePlayerViewController). After using XCDYouTubeKit the app loses the functionality specified in "Note" above means status bar starts showing up in landscape also.

You can download the demo project here.

https://www.dropbox.com/s/yp5pkvf9evsl8wb/XCDYouTubeKit%20Demo.zip?dl=0

To experience this thing you need to follow the following steps in XCDYouTubeKit demo:

  1. set "View controller-based status bar appearance" in info.plist file to "NO".
  2. Open the app in iOS 8 and go to "Full Screen Player".
  3. Change the Orientation to portrait to landscape or vice-versa. You will observe that the status bar hides in landscape but not in portrait.
  4. Now tap on "Play Full Screen" button(Portrait mode) and let the view controller come up.
  5. Dismiss the video by pressing "done" button( irrespective on orientation ).
  6. Change the Orientation to portrait to landscape or vice-versa. You will observe that the status bar stays there all the time irrespective of the device orientation.

Please help!!!

2

2 Answers

2
votes

Note too, Harsh, you can (controversially!) just use a category for that!

only once for the whole app. We do his every single time in high-volume production apps (in the objective-c era) with no problem, and I see it constantly in high-volume client projects. ... So ..

1) make a category called exactly UIViewController+HideStatusBar

@interface UIViewController (HideStatusBar)
@end
// the only practical approach for no-statusbar in iOS7,8+
@implementation UIViewController (HideStatusBar)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
-(BOOL)prefersStatusBarHidden {return YES;}
-(UIViewController *)childViewControllerForStatusBarHidden {return nil;}
#pragma clang diagnostic pop
@end

2) in your plist add

<key>UIStatusBarHidden~ipad</key>
<true/>
// that is needed if you're covering iPad; do it always for consistency

3) Do not set "Status bar is initially hidden" to "YES" in your plist.

4) Do not alter UIViewControllerBasedStatusBarAppearance.

Extended discussion.

2
votes

I couldn't find the solution for the original problem. But I managed to achieve the ultimate goal i.e. status bar stopped showing in landscape for (iOS 8 && iPhone).

  1. I was setting "View controller-based status bar appearance" to NO because I had to set the status style light through out the app.
  2. But as setting "View controller-based status bar appearance" to NO was causing the main problem, I removed it, which resulted in status bar black through out the app but solved main problem.
  3. Then I had to put the following code in all independent view controllers:

    -(UIStatusBarStyle)preferredStatusBarStyle {
      return UIStatusBarStyleLightContent;
     }
    

and for those view controller which were contained in UINavigationController i took the reference from following question:

preferredStatusBarStyle isn't called