2013-11-01 82 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]; 
     } 
    } 
}