在我的webViewDidFinishLoad
方法中,我有以下代码:
- (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;
}];
}
}
}
如您所见,如果快速调用此方法,例如一个具有重定向的网站,我else
中的else if
变得毫无用处。如何阻止它被如此迅速地召唤?
答案 0 :(得分:1)
不幸的是,你不能这样做。当UIWebView
开始加载新网址时,它会调用。相反,你可以做一件事。
实现委托功能
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
当新框架即将开始加载UIWebView
时,将调用此委托。
您可以通过选中可以获得值的navigationType
UIWebViewNavigationTypeLinkClicked
UIWebViewNavigationTypeFormSubmitted
UIWebViewNavigationTypeBackForward
UIWebViewNavigationTypeReload
UIWebViewNavigationTypeFormResubmitted
UIWebViewNavigationTypeOther
注意:如果您允许webview加载其他网页YES
,请返回NO
。
希望这对你有所帮助。
答案 1 :(得分:1)
- (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;
}];
}
}
}