2013-11-01 83 views
0

我有uiwebview,我想防止重新加載當前的網址,當我從縱向更改方向風景,反之亦然。UIWebView阻止重新加載時,interfaceorientation更改

你有什麼想法嗎?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    website.delegate = self; 
    [self home]; 
} 

- (void)home { 
    // Create a URL object 
    NSURL *isuURL = [NSURL URLWithString: @"http://www.example.com"]; 
    // URL Request Object 
    NSURLRequest *requestObject = [NSURLRequest requestWithURL:isuURL]; 
    // Load the request in the UIWebView 
    [website loadRequest:requestObject]; 
} 

回答

1

我認爲這是幫助你:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) 
{ 
    [website stopLoading]; 
} else if ([website isLoading]) 
{ 
    [website reload]; // or [website loadRequest:requestObject]; 
}} 
0

試試這個:

if(! [myWebView isLoading]) 
    { 
     NSURL *isuURL = [NSURL URLWithString: @"http://www.example.com"]; 
    // URL Request Object 
    NSURLRequest *requestObject = [NSURLRequest requestWithURL:isuURL]; 
    // Load the request in the UIWebView 
    [website loadRequest:requestObject]; 
    } 
-1

非常感謝球員的幫助。

下面是最終解決我的問題

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
     if ([website isLoading]) { 
      [website reload]; 
     } 
     else { 
      [website stopLoading]; 
     } 
    } 

    else if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     if ([website isLoading]) { 
      [website reload]; 
     } 
     else { 
      [website stopLoading]; 
     } 
    } 
}