demo地址[https://github.com/shabake/GHGHAddADV]
效果图.gif0.先去缓存找图片,如果有图片直接显示在advImage在,如果没有图片就去下载.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"loading.png"]];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDir = FALSE;
BOOL isExit = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
if (isExit) {
_advImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screen_width, screen_height)];
[_advImage setImage:[UIImage imageWithContentsOfFile:filePath]];
[self.window addSubview:_advImage];
[self performSelector:@selector(removeAdvImage) withObject:nil afterDelay:3];
}else{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self loadData];
});
}
1.图片显示1秒后利用transform做动画移除advImage
[UIView animateWithDuration:1.0f animations:^{
_advImage.transform = CGAffineTransformMakeScale(0.1f, 0.1f);
_advImage.alpha = 0.f;
} completion:^(BOOL finished) {
[_advImage removeFromSuperview];
}];
网友评论