Whats the best 开发者_运维问答way to fade out a webview when its loading to make sure people know its loading?
Use a custom UIView
that is a semi-transparent gray color and display it on top of the UIWebView. This UIView's controller should be a delegate to the UIWebView
so it knows when it is done loading and can then dismiss itself. Edit: this also gives you the advantage of being able to use your own UIActivityViewIndicator
(spinning wheel) placed wherever you like to be more prominent than the status bar shared one.
Alternatively, you could subclass UIAlertView
and take out the background image (that blue box) and then show
this UIAlertView
while it is loading.
Edit for tutorial link: Tutorial Link is a tutorial telling you exactly how to do just this (method 1)
You can fade the webview's by altering the alpha in an animation sequence.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
myWebView.alpha = 0.0;
[UIView commitAnimations];
The preferred method of making the user aware of a loading webview is networkActivityIndicator
.
#pragma mark -
#pragma mark WebvView Delegates
-(void)webViewDidStartLoad:(UIWebView *)webView {
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO; // to stop it, set this to NO
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO; // to stop it, set this to NO
}
you could place a view that has a colour of black and 20% opacity over the view in order to dim it (this has the advantage that user interaction with the webview underneath will be disabled)
Why fade it out, why not just use a UIActivityIndicator
? Or use the shared one? If you really want to fade it out, you can always just create a UIView
, set the background color to black, with an alpha of say .5. Then just add it overtop of your UIWebView
while it's loading, remove it when it's done.
精彩评论