1

I have a UIViewController with a UIWebView that will eventually play a video stream. The whole app is made for portrait orientation only, but I'd like the video to play on landscape as well.

The furthest I could get was implement this method on the AppDelegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
  return [[window rootViewController] isMemberOfClass:[UIViewController class]] ?
          UIInterfaceOrientationMaskAllButUpsideDown : // If current view is the player, allow landscape
          UIInterfaceOrientationMaskPortrait;          // Otherwise, portrait-only
}

Debugging the top-most view controller, I found out that when the video player appears it is a member of UIViewController, and since my app does not display any other VC of that class (only subclasses), that would work.

It does allow me to rotate the video (and only the video), what is great, but when I close the video and the app returns to the previous VC, the navigation bar breaks: instead of having the regular 64 pt height (20 from the status bar + 44 of the navbar itself), the status bar portion goes way and the bar will be 44 pt tall only:

enter image description here

How can I improve this solution and make it work perfectly?

Guilherme
  • 7,839
  • 9
  • 56
  • 99
  • see http://stackoverflow.com/questions/17180376/ios-allow-landscape-mode-on-videos-only – egarlock Oct 14 '14 at 21:31
  • I tried that, it didn't work. There's no `MPMoviePlayerViewController` instance here. – Guilherme Oct 15 '14 at 00:05
  • Do you also get a lot of errors in your logs? I posted my question here and also linked a log with auto-layout errors: https://stackoverflow.com/questions/26598848/allow-video-on-landscape-with-only-portrait-app. The problem happens only on iOS 8 (not iOS 7). – entropid Oct 28 '14 at 01:13
  • I don't remember having any error messages like that, but in your case they're all auto layout stuff. Maybe you've added one or more unnecessary constraints by mistake that are causing trouble when the screen rotates. – Guilherme Oct 28 '14 at 11:45
  • No, as you can see the autolayout errors are related to the player itself, on which I have no control on. – entropid Oct 28 '14 at 13:37
  • I solved liked this: http://stackoverflow.com/a/26618777/959019. It's not a fix but just a workaround, but it's something. :) – entropid Oct 28 '14 at 21:27
  • That's awesome, @Entropid. I am working on another project right now, but I will try it later. – Guilherme Oct 29 '14 at 12:32
  • https://gist.github.com/a4arpan/e53979d53e79d6e4b1c5ff82724fa70b this might help someone – a4arpan May 09 '16 at 08:08

0 Answers0