2012-10-13 33 views
2

我想弄清楚如何解決這個只發生在iOS 4.3上的bug。當應用程序啓動時,它會顯示一個縮放的UI以適應UIWebView。它的表現完美無瑕,直到您捏合放大文檔,然後旋轉它,留下黑色區域。如果你不捏縮放,它不會離開黑色區域。我不明白爲什麼這是一個iOS 4.3的唯一問題。 問題的屏幕截圖:我一直在嘗試解決這個問題,現在我將非常感謝您的幫助。謝謝。iOS上的UIWebView autosize問題4.3

enter image description here

的截圖中的.xib設置:

enter image description hereenter image description hereenter image description here

我正在使用的代碼是:

.H:

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController 
{ 
    UIWebView *webView; 
} 

@property (nonatomic) IBOutlet UIWebView *webView; 

@end 

。米:

#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 

回答

1

我記得過去有一些UIWebView和旋轉的bug。我特別記得有一些渲染和調整大小的問題。誠實地說,如果它從iOS 4.3開始就起作用了,那麼我認爲你甚至不應該試圖解決這個問題 - 很可能你提出的解決方案在這一點上將是不吉利的和不相關的。

也就是說,this thread可能會幫助您解決問題。

+0

您提供的鏈接很有幫助。我猜我甚至不打算修復它,因爲iOS 4.3中幾乎沒有人還在使用它? – klcjr89

0

如果它適用於iOS6,可能是因爲shouldAutorotateToInterfaceOrientation永遠不會被調用。處理旋轉的方式在iOS6中進行了更改。它碰巧在你的代碼中工作。

另一個可能的解決方案是使用webview代理等待直到它被加載,然後將其添加到視圖。

+0

不,它也適用於iOS 5。 – klcjr89