test test
test test

Reputation: 91

UIWebView: application rotation

I want to open embed youtube video in my UIWebView and I use code below to realise it.

videoURL = @"http://www.youtube.com/embed/A9kCPgVIbH4";
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, -30, self.view.frame.size.width, 210)];
videoView.scrollView.scrollEnabled = NO;
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
videoHTML = [NSString stringWithFormat:@"\
             <html>\
             <head>\
             <style type=\"text/css\">\
             iframe {position:absolute; margin-top:0px;}\
             body {background-color:#000; margin:0;}\
             </style>\
             </head>\
             <body>\
             <iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
             </body>\
             </html>", videoURL];
[self.tableView addSubview:videoView];
[videoView loadHTMLString:videoHTML baseURL:nil];

However, there are one big problem. My application uses only UIInterfaceOrientationPortrait, but when I click on this UIWebView youtube player it opens in a full-screen mode and I become able to rotate video to landscape mode. After I have finished watching video I click "Back", and then starts all my problems. My application is also rotated to landscape mode and, as a result, it looks not good. Maybe anyone knows how to solve this problem? Just how to block UIWebView rotation, or how to block rotation at all.

In Info-plist I have already deleted all orientations except portrait, but nothing changed. Waiting for any response, Thanks!

Upvotes: 0

Views: 333

Answers (1)

Laughing_Jack
Laughing_Jack

Reputation: 1613

You might have more luck by looking at your app delegate and implementing supportedInterfaceOrientationsForWindow to only return UIInterfaceOrientationMaskPortrait.

You can also look into the supportedInterfaceOrientations function in your view controller and have that only return the portrait masks, or implement shouldAutorotate to return NO.

Upvotes: 1

Related Questions