我创建了一个UIWebView,并设置了自动旋转,代码如下:
- (void)loadView
{
self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webview.delegate = self;
webview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_darkgreen_320x312.png"]];
webview.dataDetectorTypes = UIDataDetectorTypeLink;
webview.multipleTouchEnabled = YES;
webview.scalesPageToFit = YES;
webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[webview loadHTMLString:@"<meta name=\"viewport\" content=\"width=320\">content ..." baseURL:nil];
[self.view addSubview:webview];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
当我在横屏模式下旋转而不缩放时,它能完美地工作。它将在旋转时在全屏上显示。
问题是,如果我在纵向模式下缩小或稍微缩小一点,然后在横向模式下旋转,Webview仍然以纵向模式的相同大小进行缩放,并且像图片中那样有黑色空间 > http://cl.ly/1o3c4712053C3T2C2H2z
在横屏模式下,它的宽度是正确的,480px(您可以看到其滚动条位于屏幕的最右侧)。我不明白为什么Webview不会全屏显示。
我做错了什么? 有没有办法解决这个问题? 请帮忙。
提前致谢。