美文网首页
iOS 简单实现app增加广告页 (附效果图和demo)

iOS 简单实现app增加广告页 (附效果图和demo)

作者: 翻滚的炒勺2013 | 来源:发表于2017-07-03 23:12 被阅读38次

    demo地址[https://github.com/shabake/GHGHAddADV]

    效果图.gif

    0.先去缓存找图片,如果有图片直接显示在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];
        }];
    

    相关文章

      网友评论

          本文标题:iOS 简单实现app增加广告页 (附效果图和demo)

          本文链接:https://www.haomeiwen.com/subject/uxxthxtx.html