iOS-APP启动页加载广告

本文详细介绍了如何在iOS应用启动时加载广告页,包括封装广告页、判断广告更新、广告显示逻辑以及广告页点击后的展示处理。通过异步下载图片并实现倒计时跳过功能,确保用户体验。同时,强调了广告页面与启动图的无缝衔接以提升视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目前市场上很多APP(如淘宝、美团、微博、UC)在启动图加载完毕后,还会显示几秒的广告,右上角都有个跳过按钮可以选择立即跳过这个广告,有的APP在点击广告页之后还会进入一个广告页。
他们玩的乐此不疲,产品汪们见了自然也是不会放过这个效果!

一、主要思路

  • 1. 封装广告页, 展现跳过按钮实现倒计时功能

  • 2.判断广告页面是否更新。异步下载新图片, 删除老图片

  • 3.广告页显示

  • 4.广告页点击后展示页

二、程序实现

Step1. 封装广告页, 展现跳过按钮实现倒计时功能

ZLAdvertView.h: 先封装出来广告页,露出显示广告页面方法和图片路径

1
2
3
4
5
6
7
8
/**
*  显示广告页面方法
*/
- ( void )show;
/**
  *  图片路径
  */
@property (nonatomic, copy) NSString *filePath;

ZLAdvertView.m:

定义广告显示的时间:

1
static  int  const  showtime = 3;
  1. 为广告页面添加一个点击手势,跳转到广告页面.

1
2
3
4
5
6
7
- (NSTimer *)countTimer {
     
     if  (!_countTimer) {
         _countTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
     }
     return  _countTimer;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
- (instancetype)initWithFrame:(CGRect)frame {
     
     if  (self = [super initWithFrame:frame]) {
         
         // 1.广告图片
         _adView = [[UIImageView alloc] initWithFrame:frame];
         _adView.userInteractionEnabled = YES;
         _adView.contentMode = UIViewContentModeScaleAspectFill;
         _adView.clipsToBounds = YES;
         // 为广告页面添加一个点击手势,跳转到广告页面
         UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToAd)];
         [_adView addGestureRecognizer:tap];
         
         // 2.跳过按钮
         CGFloat btnW = 60;
         CGFloat btnH = 30;
         _countBtn = [[UIButton alloc] initWithFrame:CGRectMake(kscreenWidth - btnW - 24, btnH, btnW, btnH)];
         [_countBtn addTarget:self action:@selector(removeAdvertView) forControlEvents:UIControlEventTouchUpInside];
         [_countBtn setTitle:[NSString stringWithFormat:@ "跳过%d" , showtime] forState:UIControlStateNormal];
         _countBtn.titleLabel.font = [UIFont systemFontOfSize:15];
         [_countBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
         _countBtn.backgroundColor = [UIColor colorWithRed:38 /255.0 green:38 /255.0 blue:38 /255.0 alpha:0.6];
         _countBtn.layer.cornerRadius = 4;
         
         [self addSubview:_adView];
         [self addSubview:_countBtn];
         
     }
     return  self;
}
1
2
3
4
5
- ( void )setFilePath:(NSString *)filePath {
     
     _filePath = filePath;
     _adView.image = [UIImage imageWithContentsOfFile:filePath];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值