UIWebView not changing orientation on switch to landscape
I am making a UIWebView like this (case 2):
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
CGRect frame = CGRectMake(0, 0, 320, 400);
SongDetailsTVC *infoVC;
UIWebView *ytView;
NSString *htmlVideoHTML, *html;
UIViewController *youtubeController;
switch (buttonIndex) {
case 0:
[self swapLanguage];
break;
case 1:
infoVC = [[SongDetailsTVC alloc] initWithStyle:UITableViewStyleGrouped];
[infoVC setSongData:songData];
[infoVC setTitle:@"Song Info"];
[[self navigationController] pushViewController:infoVC animated:YES];
[infoVC release];
break;
case 2:
// HTML to embed YouTube video
htmlVideoHTML = @"<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
html = [NSString stringWithFormat:htmlVideoHTML, [songData objectForKey:@"YouTube Link (Value)"], frame.size.width, frame.size.height];
// Load the html into the webview 开发者_运维问答
ytView = [[UIWebView alloc] initWithFrame:frame];
[ytView setMediaPlaybackRequiresUserAction:NO];
[ytView loadHTMLString:html baseURL:nil];
youtubeController = [[UIViewController alloc] init];
[youtubeController setView:ytView];
[youtubeController setTitle:@"YouTube Video"];
[[self navigationController] pushViewController:youtubeController animated:YES];
[ytView release];
[youtubeController release];
break;
default:
break;
}
}
The problem is that, when I switch to landscape mode, it doesn't change its orientation. What am I doing wrong? Thanks.
Rotation is determined by the view controller, not the view. UIViewController's default implementation of shouldAutorotateToInterfaceOrientation:
returns YES only for portrait; you will have to create a subclass of UIViewController, override that method, and use that subclass instead of a stock UIViewController.
UIWebView
has a very naive method of determining orientation from the standpoint of e.g. CSS3 media queries.
Basically if it's wider than it is tall, it's considered landscape, and if it's taller than it is wide, it's considered portrait. Since your web view is fixed at 320 x 400, it will always return portrait.
精彩评论