Resolved UIWebView autosize issue only on iOS 4.3

Discussion in 'iOS Programming' started by troop231, Oct 12, 2012.

  1. troop231, Oct 12, 2012
    Last edited: Oct 17, 2012

    troop231 macrumors 603

    Joined:
    Jan 20, 2010
    #1
    I am trying to figure out how to fix this bug that only occurs on iOS 4.3. When the application launches, it displays a PDF that is scaled to fit in the UIWebView. It behaves perfectly until you pinch to zoom on the document, and then rotate it, leaving behind a black area. If you don't pinch to zoom, it doesn't leave the black area. I don't understand why this is a iOS 4.3 only issue. I've been trying to solve this problem awhile now, and would greatly appreciate your help. Thank you.

    Screenshot of the issue:

    [​IMG]

    Screenshots of the .xib settings:

    [​IMG] [​IMG] [​IMG]

    The code I'm using is:

    .h:
    Code:
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    {
       UIWebView *webView;
    }
    
    @property (nonatomic) IBOutlet UIWebView *webView;
    
    @end
    .m:
    Code:
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    @synthesize webView;
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation
    {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        return YES;
        } else {
        return (interfaceOrientation !=
                UIInterfaceOrientationPortraitUpsideDown);
        }
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];
    
        NSURL *url = [NSURL fileURLWithPath:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    
        [webView loadRequest:requestObj];
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
    }
    
    @end
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Is that black area part of the webview or another view? Does this happen with other pdf files or other content in the web view? Is the webview inside another view?
     
  3. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #3
    The black part is part of the webView. It happens with all PDFs and webpages. The webview is inside of the main view in the .xib.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    What is the iOS deployment target for the xib file? It's listed in one of the tabs in the views on the right. Is it possible that it's 5 or greater?
     
  5. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #5
    This is what it is:

    [​IMG]
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    Dunno.

    Does your app have a container view controller like a nav controller or tab bar controller?

    Do you set the Window's rootViewController?
     
  7. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #7
    I don't have a nav or tab bar based app. I actually created this app as a single view based application to test and work out the webView resize bug in my real applications. So far I can't fix it.
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    I recommend that you use a UINavigationController as a container view controller. If you don't want to see the navbar then make it hidden.

    Does your real app have a container view controller?
     
  9. troop231, Oct 15, 2012
    Last edited: Oct 15, 2012

    troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #9
    My real app is a navigation based app, and the problem exists there as well on iOS 4.3.

    Edit: I just made a quick sample tab bar based app, and the issue/bug is still there:

    [​IMG]
     
  10. troop231 thread starter macrumors 603

    Joined:
    Jan 20, 2010
    #10

Share This Page