5

我的 UIWebView 有问题。当视图加载时,它可以很好地加载任何方向,完美地填充整个页面等。

但是,如果我以纵向加载它,然后旋转设备,webview 不会一直填充到右侧,我终生无法弄清楚原因。

这是我的观点确实加载方法

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib

    if  ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait){

        self.measurementsWebView.frame = CGRectMake(0, 0, 320, 367);

    }else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight){

        self.measurementsWebView.frame = CGRectMake(0, 0, 480, 218);
    }

    NSString *path = [[NSBundle mainBundle] pathForResource:@"measurements" ofType:@"png"];
    [measurementsWebView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];
    measurementsWebView.scalesPageToFit = YES;

}

如果我查看界面生成器,我试图找到允许我设置扩展宽度或您所称的面板的面板,但我能看到的就是这个。

在此处输入图像描述

任何帮助将不胜感激

4

3 回答 3

4

除了手动设置框架,您还可以将自动调整大小的蒙版设置为:

measurementsWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

如果屏幕上没有其他元素,它将调整 webView 的大小(根据调整大小时使用的值,我认为你没有measurementsWebView)。或者,直接来自笔尖,如下图所示:

从笔尖自动调整大小

可以通过单击左下角名为Autosizing的框中的红色条来设置蒙版。

于 2012-07-09T05:00:29.617 回答
3

viewDidLoad运行一次 - 当视图加载时。

如果您想在发生旋转时手动调整框架,请添加代码以调整其大小,viewDidLayoutSubviews每当视图旋转时都会调用该代码。

-(void)viewDidLayoutSubviews {

    [super viewDidLayoutSubviews];

    self.measurementsWebView.frame = self.view.bounds;

}
于 2014-06-25T00:05:53.203 回答
1

在界面生成器中,显示“布局矩形”的下拉菜单,单击它并选择“框架矩形”。

或者,您可以覆盖willAnimateRotationToInterfaceOrientation:视图控制器中的方法并手动设置坐标/大小,就像您在viewDidLoad.

于 2012-07-09T00:00:16.017 回答