2012-07-08 60 views
5

我遇到了与我的UIWebView有关的问题。当视图加载它在任何方向加载它的罚款,完全填充整个页面等。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; 

} 

如果我看在界面生成器,我试图找到,让我来设置扩大宽度,或者你叫它什么都面板,但我可以看到这是。

enter image description here

任何帮助,将不胜感激

回答

1

在界面生成器,下拉菜单的地方说:“布局矩形”,单击它并选择“矩形框架”。

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

+0

奇怪的是,即使我这样做,它不改变菜单的外观......我想也许我需要重新安装xcode。我会尝试shouldAutototateToInterfaceOrientation现在..但是,这将改变UIView帧的大小,以适应水平视图。 – HurkNburkS 2012-07-09 01:00:39

+0

对不起,我的意思是写'willAnimateRotationToInterfaceOrientation:'方法。与您在'viewDidLoad'方法中检查方向的方式类似,您可以在此执行同样的操作并调整视图的框架。 – sooper 2012-07-09 01:21:38

+0

对于你的界面生成器的问题,我建议你阅读这篇文章[这里](http://stackoverflow.com/questions/9370072/xcode-4-3-not-presenting-autoresizing-panel-in-size-inspector ) – sooper 2012-07-09 01:27:37

4

除了手动设置框,你也可以设置自动调整大小面具为:

measurementsWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

将调整webView的情况下,你在屏幕上有没有其他元素(其中,我采取它,你没有,从你调整measurementsWebView时使用的值)。或者,直接从如下图所示的笔尖:

auto-resize from nib

面具可以通过点击在框中红柱设置称为自动调整大小朝左下方。

3

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

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

-(void)viewDidLayoutSubviews { 

    [super viewDidLayoutSubviews]; 

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

} 
+0

简单而简单,谢谢 – peroija 2015-05-22 13:12:08