3
votes

I create UIWebView and set autorotate like this:

- (void)loadView
{
    self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];

    UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    webview.delegate = self;
    webview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_darkgreen_320x312.png"]];
    webview.dataDetectorTypes = UIDataDetectorTypeLink;
    webview.multipleTouchEnabled = YES;
    webview.scalesPageToFit = YES;
    webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [webview loadHTMLString:@"<meta name=\"viewport\" content=\"width=320\">content ..." baseURL:nil];
    [self.view addSubview:webview];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

It works perfectly when I rotate it in landscape without zooming. It will display full screen on both rotation.

The problem is if I zoom-out or a little bit zoom-in in portrait mode and then rotate it in landscape, webview still zoom with the same size of portrait mode and it has black space like in picture > http://cl.ly/1o3c4712053C3T2C2H2z

It's width in landscape is correct, 480px (you can see its scrollbar is on most right of screen). I don't understand why webview don't display full screen.

What I do wrong? Is there any way to fix this? Please help.

Thanks in advance.

1
Did you manage to solve this problem??Vin
I found that other application also has this problem (such as Facebook). I think it's bug from apple ...?Dolly
Have the same problem - the problem is solved in this thread: stackoverflow.com/questions/2890673/…Kevin Franklin

1 Answers

0
votes

In order to achieve your effect you need to set the zoomScale to 0 on rotation. See my full answer here: UIWebView content not adjusted to new frame after rotation