当界面定位发生变化时,UIWebView会阻止重新加载

时间:2013-11-01 11:05:46

标签: ios iphone uiwebview

我有uiwebview,当我将方向从纵向更改为横向时,我希望阻止重新加载当前网址,反之亦然。

你有什么想法吗?

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

3 个答案:

答案 0 :(得分: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];
}}

答案 1 :(得分: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];
    }

答案 2 :(得分:-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];
        }
    }
}