UIWebView通过IB创建,并且通过代码不是方向友好的

时间:2013-02-08 09:17:11

标签: ios uiwebview landscape uiinterfaceorientation portrait

我在viewDidLoad中写这个,

// Programmatically creating uiwebview. 
UIWebView *webVPrg = [[UIWebView alloc] initWithFrame:self.view.frame];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSMutableURLRequest *urlReq = [[NSMutableURLRequest alloc] initWithURL:url];
[self.view addSubview:webVPrg];
[webVPrg loadRequest:urlReq];

此处创建的Web视图无法正确对齐纵向和横向,而如果Web视图通过Interface Builder 创建,则可以正常工作。

(不确定 initWithFrame:self.view.frame 是否有问题)

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您应该设置autoresizingMask

webVPrg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

使视图根据其超级视图自动调整其大小。您也可能需要对self.view执行相同操作。