dhrm
dhrm

Reputation: 14934

UIView with rotation issues

I've a sample project, where I'm creating an custom 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

Two UIWebView's are created inside the viewWillAppear:animated and stored in an array -- and than the first UIWebView is added to the subview of self.view. When a button in the navigation bar is pressed, the first UIWebView will be removed from the subview and the next one will be added instead.

The problem is, that if I'm running the application in landscape (both iPhone and iPad) after the second UIWebView is added, the WebView is not filling the entire screen. Why?

enter image description here

You can download the small sample project here: http://uploads.demaweb.dk/WebView.zip.

Upvotes: 0

Views: 99

Answers (1)

Ankit Srivastava
Ankit Srivastava

Reputation: 12405

I dont know why but this inside your action method will do the trick...

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

hope this helps.. :/

Upvotes: 1

Related Questions