Objective c UIView存在轮换问题

Objective c UIView存在轮换问题,objective-c,cocoa-touch,uiview,Objective C,Cocoa Touch,Uiview,我有一个示例项目,我正在其中创建一个自定义UIViewController #import "ViewController.h" @implementation ViewController @synthesize webViews = _webViews; @synthesize webView = _webView; - (void)setWebView:(UIWebView *)webView { if (webView!=_webView) { [self.

我有一个示例项目,我正在其中创建一个自定义UIViewController

#import "ViewController.h"

@implementation ViewController

@synthesize webViews = _webViews;
@synthesize webView = _webView;

- (void)setWebView:(UIWebView *)webView {
    if (webView!=_webView) {
        [self.webView removeFromSuperview];
        _webView = nil;
        _webView = webView;
        [self.view addSubview:self.webView];
        [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]]];
    }
}

- (IBAction)newWebView:(id)sender {
    self.webView = [self.webViews objectAtIndex:1];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    UIWebView *webView1 = [[UIWebView alloc] initWithFrame:self.view.bounds];
    webView1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    UIWebView *webView2 = [[UIWebView alloc] initWithFrame:self.view.bounds];
    webView2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.webViews = [NSArray arrayWithObjects: webView1, webView2, nil];

    self.webView = [self.webViews objectAtIndex:0];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

@end
将在
视图中创建两个UIWebView:已设置动画的
并存储在一个数组中,然后将第一个UIWebView添加到self.view的子视图中。当按下导航栏中的按钮时,将从子视图中删除第一个UIWebView,并添加下一个UIWebView

问题是,如果我在添加第二个UIWebView后在横向(iPhone和iPad)中运行应用程序,WebView不会填满整个屏幕。为什么?


你可以在这里下载这个小样本项目:。

我不知道为什么,但是这个在你的行动方法中会起作用

UIWebView *newWebView=[[UIWebView alloc] init];
    newWebView=[self.webViews objectAtIndex:1] ;
    newWebView.frame=self.view.frame;
    self.webView = newWebView;
希望这有助于/