Geo*_*day 9 xcode uiwebview ios
我试图使用设备的整个屏幕在UIWebview中显示pdf,状态栏和顶栏除外.到目前为止,我IBOutlet UIWebview *webview;在.h文件中创建了.我在我的故事板中连接了webview,并在我的.m文件中编写了以下代码:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
pdf在我的3.5英寸显示正确,但在我的4英寸显示屏中,底部被切断.当我旋转到横向视图时,这更加明显.大约33%的屏幕根本没有使用.我怎样才能解决这个问题?我知道它必须与我上面的代码(webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];)中的UIWebview维度有关,但有没有更好的方法来简单地在整个屏幕上显示webview,而无需指定特定的屏幕高度和宽度?
Hal*_*alR 30
一件便宜的事情就是在覆盖中设置webview的框架 - (void)viewDidLayoutSubviews
- (void)viewDidLayoutSubviews {
webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
这里做的好处是,这里已经确定了视图的大小和方向,您可以获得准确的测量结果.
| 归档时间: |
|
| 查看次数: |
32763 次 |
| 最近记录: |