In my webViewDidFinishLoad method, I have the following code:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
if (hasPressed == 1) {
hasPressed = 0;
isBlocked = 0;
}
else if (hasPressed == 0 && hasDroppedDown == 0) {
if (viewState != kStateWeather || isBlocked == 0) {
[UIView animateWithDuration:0.5
delay:0.0 options:UIViewAnimationCurveLinear animations:^{
//Animations
}
completion:^(BOOL finished){
hasDroppedDown = 1;
}];
}
}
}
As you can see, if this method is called rapidly, e.g. a website that has a redirect, the else in my else if becomes useless. How do I stop it from being called so rapidly?
Unfortunately, you cant do that. It will call when ever a new URL is start loading in the UIWebView. Instead you can do one thing.
Implement the delegate function
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
This delegate will be called when a new frame is about to start loading in the UIWebView.
You can figure out which type of request is going to load by checking the navigationType which can attain values
UIWebViewNavigationTypeLinkClicked
UIWebViewNavigationTypeFormSubmitted
UIWebViewNavigationTypeBackForward
UIWebViewNavigationTypeReload
UIWebViewNavigationTypeFormResubmitted
UIWebViewNavigationTypeOther
Note: return YES if you allow the webview to load the page else NO.
Hope this help you.
- (void)main { //being called every 0.2
t+=0.2;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
loadImg.hidden = 1;
m_activity.hidden= TRUE;
[m_activity stopAnimating];
if (t>0.5) {
[self finishedLoading];
t=0;
}
}
- (void)finishedLoading {
if (hasPressed == 1) {
hasPressed = 0;
isBlocked = 0;
}
else if (hasPressed == 0 && hasDroppedDown == 0) {
if (viewState != kStateWeather || isBlocked == 0) {
[UIView animateWithDuration:0.5
delay:0.0 options:UIViewAnimationCurveLinear animations:^{
//Animations
}
completion:^(BOOL finished){
hasDroppedDown = 1;
}];
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With