我创建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仍然使用相同尺寸的肖像模式进行缩放,并且它具有黑色空间,如图片&gt; http://cl.ly/1o3c4712053C3T2C2H2z
它的横向宽度是正确的,480px(你可以看到它的滚动条位于屏幕的最右侧)。我不明白为什么webview不能全屏显示。
我做错了什么? 有没有什么办法解决这一问题? 请帮忙。
提前致谢。
答案 0 :(得分:0)
为了达到效果,您需要在旋转时将zoomScale设置为0。请在此处查看完整答案:UIWebView content not adjusted to new frame after rotation