0

我有 uiwebview,当我将方向从纵向更改为横向时,我想防止重新加载当前 url,反之亦然。

你有什么主意吗?

- (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];
}
4

3 回答 3

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];
}}
于 2013-11-01T12:54:40.903 回答
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];
    }
于 2013-11-01T12:35:47.533 回答
-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];
        }
    }
}
于 2013-11-01T19:38:24.353 回答