Question

I am developing and app which i want a youtube video in a page. It works fine withe the code below:

-(void)viewDidLoad{
    [super viewDidLoad];

}

- (void) viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.47 green:.43 blue:.4 alpha:1];

}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    NSString *htmlString;
    if(interfaceOrientation == UIInterfaceOrientationPortrait){
        htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 20\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"768\" height=\"960\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"768\" height=\"960\"></embed></object></div></body></html>",urlToOpen,urlToOpen];

    }else{
        htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"1024\" height=\"704\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"1024\" height=\"704\"></embed></object></div></body></html>",urlToOpen,urlToOpen];

    }
    [self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
    return  YES;
}

The view is working fine in portrait and in landscape. The problem is when i see the video with the full Screen and i Rotate. Whe i finish the full screen, the webview didn't detect the rotation and print the webview as the wrong way.

How could i detect the Youtube full screen is rotating for rotate my view?

Thankyou

Was it helpful?

Solution

set content width to 100%

my template

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \
<html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> \
<meta name=\"viewport\" content=\"width=320\"> \
<style> \
html,body {-webkit-text-size-adjust: none; size:100%%} \
body {margin: 0; padding: 0;width:100%;} \
table { font-family:Georgia; font-size:%dpt; border-style: none; size:100%%} \
</style> </head>

....

OTHER TIPS

I'm assuming your already handling the orientation callbacks? (shouldAutorotateToInterfaceOrientation, didRotateFromInterfaceOrientation)

When the YouTube video finishes and focus is returned to your app, the viewWillAppear method should be called. In there, you can get the device orientation:

UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;

Then perform your layout changes. This also would handle the layout when this view first opens.

You could do it in a switch statement:

switch(orientation) {
    case UIInterfaceOrientationLandscapeLeft:  //layout for this landscape mode
    case UIInterfaceOrientationPortraitUpsideDown:  //layout for this portrait mode

I handled that problem using NSNotification like this

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerDidExitFullScreen)
                                             name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                           object:nil];

and method that will be called is

- (void)moviePlayerDidExitFullScreen
{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    {
        [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
    }
}

Hope that Helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top