Michael
Michael

Reputation: 373

Fullscreen youtube video, rotation, and the status bar (iOS)

I came across an issue in my current project, so I spun up a simple app to see if I could isolate the problem. In my app delegate I hide the status bar.

[application setStatusBarHidden:YES animated:NO];

In my single view controller I have this code:

- (void)loadVideo
{
    // HTML to embed YouTube video
    NSString *youTubeVideoHTML = @"<html><head>\
    <body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";

    // Populate HTML with the URL and requested frame size
    NSString *html = [NSString stringWithFormat:youTubeVideoHTML, @"http://www.youtube.com/watch?v=VDRoBnL1gRg", 500, 500];

    // Load the html into the webview
    [self.webview loadHTMLString:html baseURL:nil];
}

The app is also set to autorotate.

Now, here's the problem: When I play the youtube video, enter fullscreen mode, rotate the device 90 degrees, and hit "Done" to exit fullscreen, the entire interface remains shifted down 20px as if it were accommodating a status bar. I noticed that when viewing a video in full screen, ios adds a status bar, so I'm guessing that's part of the issue. I've seen the problem occur with the native video player as well.

Any ideas?

Upvotes: 6

Views: 3404

Answers (4)

BananaM0ntana
BananaM0ntana

Reputation: 39

I used this YouTube embed method recently for my app Game Guide: Black Ops 2, and I was having this problem along with being shown the rootViewController when hitting the movie player's "done" button. Checking "Wants Full Screen" on the rootViewController fixed the 20 pixel shift, and to fix the rootViewController being displayed after pushing the "done" button I added this to the rootViewController which was adding a UIViewController (with tableView) as a child which was using [presentViewControllerAnimated:(BOOL) completion:nil] to show the ViewController with the YouTube Video Embed.

Now everything is working perfectly... check out the Videos tab in my app if you want to see how it behaves.

-(void)viewDidAppear:(BOOL)animated {
    NSLog(@"Main View viewDidAppear...");
    [super viewDidAppear:animated];
    [self dismissViewControllerAnimated:YES completion:nil];

}

Upvotes: 3

user1350188
user1350188

Reputation: 11

I had a similar problem.

I created views in storyboard. Checking Wants full Screen in layout section of view controller settings solved it for me.

Upvotes: 1

alexmorhun
alexmorhun

Reputation: 1983

To try to add to your info.plist next key: UIStatusBarHidden ("Status bar is initially hidden") with value YES.

Upvotes: 0

picciano
picciano

Reputation: 22701

If by any chance you're using a UITabBarController, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

Upvotes: 0

Related Questions