UIWebview全屏大小 [英] UIWebview full screen size
问题描述
我正在尝试使用设备的整个屏幕在UIWebview中显示pdf,状态栏和顶栏除外。到目前为止,我在.h文件中创建了 IBOutlet UIWebview * webview;
。我在我的故事板中连接了webview并在我的.m文件中编写了以下代码:
I am trying to display a pdf in a UIWebview using the entire screen of the device, except the status bar and top bar. So far, I created IBOutlet UIWebview *webview;
in my .h file. I connected the webview in my storyboard and wrote the following code in my .m file:
- (void)viewDidLoad
{
[super viewDidLoad];
webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webview.scalesPageToFit = YES;
webview.autoresizesSubviews = YES;
webview.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[webview setBackgroundColor:[UIColor clearColor]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Chart" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webview loadRequest:request];
[self.view addSubview:webview];
}
pdf在我的3.5英寸中正确显示,但在我的4英寸显示屏,底部被切断。当我旋转到横向视图时,这更加明显。大约33%的屏幕根本不使用。我怎样才能解决这个问题?我知道它必须与上面代码中的UIWebview维度有关( webview = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,460)];
),但有没有更好的方法可以在整个屏幕上简单地显示webview,而无需指定特定的屏幕高度和宽度?
The pdf displays correctly in my 3.5 inch, but in my 4 inch display, the bottom is cut off. This is even more noticeable when I rotate to landscape view. About 33% of the screen is not used at all. How can I fix this? I know it must have something to do with the UIWebview dimensions in my code above (webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
), but is there a better way to simply display the webview on the entire screen, without specifying a specific screen height and width?
推荐答案
一件便宜的事情是设置webview的框架覆盖 - (void)viewDidLayoutSubviews
One cheap thing to do would be to set the frame of the webview in overriding - (void)viewDidLayoutSubviews
- (void)viewDidLayoutSubviews {
webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
这里做的好处是,视图的大小和方向已在此处确定,您可以获得准确的测量结果。
the advantage of doing it here, is that the size and orientation of the view has already been determined here, and you can get an accurate measurement.
这篇关于UIWebview全屏大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!