IOS-开屏广告页

  • 思路
    在一个新的UIWindow的最上层添加一个控制器 用SDWebImage异步加载从接口获取的图片,把图片平铺在这个控制器上。最后配合UIView的渐隐动画再几秒后移除这个控制器

  • 注意
    为了不对Appdelegate有更多的入侵 我们写了一个UIWindow的Category,命名为Expand

  • 在Appdelegate的中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:kScreenBounds];
    
    self.mainViewController = [[MainController alloc] init];

    self.window.rootViewController = self.mainViewController;
    [self.window makeKeyAndVisible];
    
    [self.window showLanuchPageAndSetUmeng];
    
    return YES;
}
  • 在UIWindow+Expand中
- (void)showLanuchPageAndSetUmeng{

    LaunchViewController *launchVC = [[LaunchViewController alloc] init];
    //在新的windon上添加一个控制器LaunchViewController
    [self addSubview:launchVC.view];

}
  • 在LaunchViewController.m中
#import "LaunchViewController.h"
#import "UIImageView+WebCache.h"

static CGFloat const animationDuration = 3.0;

@interface LaunchViewController ()

@property (nonatomic, strong) UIImageView *launchImage;

@end

@implementation LaunchViewController

#pragma mark - life cycle

- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self.view addSubview:self.launchImage];
//    把开屏广告页置于这个控制器的最上层
    [self.view bringSubviewToFront:self.launchImage];
    [self.view addSubview:self.imageTitle];
//    获得启动动画图片
    [self updateLanunchImage];

}

#pragma mark - private method
- (void)updateLanunchImage{
    
    [HttpTool get:@"http://news-at.zhihu.com/api/4/start-image/1080*1776" params:nil success:^(id json) {
       //从接口获取图片转为model赋值给LaunchImage这个类里的img
        LaunchImage *lanunchImage = [LaunchImage mj_objectWithKeyValues:json];
        
        SDWebImageManager *manger = [SDWebImageManager sharedManager];
        
        [manger downloadImageWithURL:[NSURL URLWithString:lanunchImage.img] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            
            nil;
            
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
     
            self.launchImage.image = image;

            [UIView animateWithDuration:animationDuration animations:^{
                _launchImage.transform = CGAffineTransformMakeScale(1.2, 1.2);
            } completion:^(BOOL finished) {
                  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.view removeFromSuperview];
                });         
         }];
        }];
        
    } failure:^(NSError *error) {
        
    }];
}

#pragma mark - getter and setter

- (UIImageView *)launchImage{
    if (_launchImage == nil) {
        _launchImage = [[UIImageView alloc] initWithFrame:kScreenBounds];
        _launchImage.image = [UIImage imageNamed:@"Default"];
    }
    return _launchImage;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,255评论 4 61
  • 最近一朋友正准备跳槽,就从各处搜索整理一些基础,便于朋友复习,也便于自己复习查看. 1. 回答person的ret...
    smile丽语阅读 1,802评论 0 7
  • 昨晚看到这样一首诗,忽然感触很深,随着年纪渐增,我本已渐渐对许多感受钝化,却还会在这首诗面前感到一股沉甸甸...
    紫轻离阅读 285评论 0 0
  • 01 大学时期有个朋友,来自于一个比较遥远的村落,村里很难出一个大学生,而且还是一个漂亮的姑娘,在重男轻女的村庄里...
    大头针思维阅读 525评论 1 4
  • 该是个开心的事情的,却因为我的个人原因,惹得大家都不痛快。我从来都是这样,见不得别人好吗?当然不是,朋友拿到原创标...
    刘安忆晨阅读 741评论 4 5