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的是本viewWillAppear:animated
內創建並存儲在一個陣列 - 和比第一的UIWebView加到self.view的子視圖。當按下導航欄中的按鈕時,將從子視圖中刪除第一個,並將添加下一個。
問題是,如果我在添加第二個UI之後運行橫向應用程序(包括iPhone和iPad),則WebView不會填滿整個屏幕。爲什麼?
您可以在這裏下載小樣本項目:http://uploads.demaweb.dk/WebView.zip。