在@implementation AppDelegate的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
NSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
UIImage * imageFromWeb = [self loadImage:@"MyImage" ofType:@"jpg" inDirectory:documentsDirectoryPath];
if (imageFromWeb) {
WCImageView *imageV = [[WCImageView alloc] initWithFrame:self.window.frame];
imageV.image = imageFromWeb;
[imageV startShowingPage];
}
else {
[WCImageView loadingImageDataFromWeb];
}
其中方法:
-(UIImage *) loadImage:(NSString *)fileName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {
UIImage * result = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", directoryPath, fileName, extension]];
return result;
}
WCImageView类实现:
#import <UIKit/UIKit.h>
#import "KKProgressTimer.h"
@interface WCImageView : UIImageView <KKProgressTimerDelegate>
- (void)startShowingPage;
+ (void)loadingImageDataFromWeb;
@end
#import "WCImageView.h"
#import "MFService.h"
#import "Utilities.h"
#import "UIColor+extend.h"
#define DEFAULT_TIMEROUT 4.f
static UIWindow *__sheetWindow = nil;
@implementation WCImageView
{
KKProgressTimer *timer1;
}
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
}
return self;
}
#pragma mark - PUBLIC METHODS
- (void)startShowingPage {
[self addWindowAction];
}
+ (void)loadingImageDataFromWeb {
NSString *timestamp = [Utilities getTimestamp];
NSDictionary *paramters = @{ @"spid":SPID, @"timestamp":timestamp,
@"hash":[Utilities getHash:timestamp],
@"citycode":@""};
NSDictionary *serviceDict = [[MFServiceList manager] queryActionWithId:NO_18_queryPageThemes];
MFService *service = [[MFService alloc] initWithDataDictionary:serviceDict];
[service queryWith:paramters success:^(id result) {
NSDictionary *dict = (NSDictionary *)result;
NSDictionary *data = dict[@"data"];
NSDi