我创建UIWebView并设置autorotate像这样:
- (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不能全屏显示。
我做错了什么?
有没有什么办法解决这一问题?
请帮忙。
提前致谢。
最佳答案
为了达到您的效果,您需要在旋转时将zoomScale设置为0。在这里查看我的完整答案:UIWebView content not adjusted to new frame after rotation
关于iphone - 如何在景观中以正确的缩放比例显示UIWebView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5817654/