2012-02-20 15 views
0

私はカスタムのUIViewControllerを作成しているサンプルプロジェクトがあります。回転の問題を伴うUIView

#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「sはviewWillAppear:animated内に作成し、配列に格納されている - 第のUIWebViewよりself.viewのサブビューに追加されます。ナビゲーションバーのボタンを押すと、最初のUIWebViewがサブビューから削除され、次のサブビューが追加されます。

2番目のUIWebViewが追加された後、私がアプリケーションを風景(iPhoneとiPadの両方)で実行していると、WebViewが画面全体を満たしていないという問題があります。どうして? http://uploads.demaweb.dk/WebView.zip

enter image description here

あなたはここに小さなサンプルプロジェクトをダウンロードすることができます。私はなぜ知っているが、これはあなたのアクションメソッド内でトリックを行いますいけない

答えて

1

...

UIWebView *newWebView=[[UIWebView alloc] init]; 
    newWebView=[self.webViews objectAtIndex:1] ; 
    newWebView.frame=self.view.frame; 
    self.webView = newWebView; 

はこれが役に立てば幸い..:/