only display loading view once per page load

This commit is contained in:
Sami Samhuri 2011-12-26 22:41:14 -05:00
parent f441071fd8
commit efb8d95545
2 changed files with 21 additions and 3 deletions

View file

@ -11,14 +11,20 @@
#import "InstapaperCredentials.h"
#import "UIAlertView+marshmallows.h"
// Private API
@interface SSDetailViewController ()
{
UIBarButtonItem *_showsButton;
}
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
@property BOOL isLoading;
- (void) configureView;
@end
@implementation SSDetailViewController
@synthesize episode = _episode;
@ -29,6 +35,7 @@
@synthesize instapaperButton = _instapaperButton;
@synthesize loadingView = _loadingView;
@synthesize masterPopoverController = _masterPopoverController;
@synthesize isLoading = _isLoading;
#pragma mark - Managing the detail item
@ -90,15 +97,24 @@
}
}
- (BOOL) webView: (UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType: (UIWebViewNavigationType)navigationType
{
self.isLoading = navigationType == UIWebViewNavigationTypeOther ? self.isLoading : YES;
return YES;
}
- (void) webViewDidStartLoad: (UIWebView *)webView
{
[UIView animateWithDuration: 1.0 animations: ^{
self.loadingView.alpha = 1.0;
}];
if (self.isLoading) {
[UIView animateWithDuration: 1.0 animations: ^{
self.loadingView.alpha = 1.0;
}];
}
}
- (void) webViewDidFinishLoad: (UIWebView *)webView
{
self.isLoading = NO;
[UIView animateWithDuration: 0.3 animations: ^{
self.loadingView.alpha = 0.0;
}];
@ -108,6 +124,8 @@
- (IBAction) goHome: (id)sender
{
// Show the loading animation
self.isLoading = YES;
if (self.episode) {
[self.webView loadRequest: [NSURLRequest requestWithURL: self.episode.url]];
}