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。