1、先看效果
2、模板的介绍
1》样式 (2种)
全屏 :FullScreen
四分屏:FourPointScreen
2》效果
效果有动态和静态两种。如展示效果1所示。
3、优点介绍
对于广告页,想必不同的开发者各有各的写法。而我的广告页面的优点是:
1》可加载动态和静态的图片
2》对加载的广告页数据进行缓存
3》支持广告页的缓存数据的更新
4》加载速度快。
4、知识点的介绍
本特辑含有许多知识点,分别如下:
1、从写一个类,注意布局和数据添加的程序。(这个就不多说了,开发者应该会哦!)
2、倒计时定时器
倒计时,网上很多,开发者可自行选择,我的可能还没你的好。本特辑的倒计时代码:
__block NSInteger timeCount = timeValue;
timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
dispatch_source_set_event_handler(timer, ^{
if (timeCount<=1) {
/* 停止定时*/
dispatch_source_cancel(timer);
dispatch_async(dispatch_get_main_queue(), ^{
/* 删除广告页*/
[self deleteAdvertisement:1000];
});
}else{
dispatch_async(dispatch_get_main_queue(), ^{
SkipLable.text = [NSString stringWithFormat:@"%ld跳过",(long)timeCount];
});
timeCount--;
}
});
dispatch_resume(timer);
3、 多焦点的处理
#pragma mark --- gestureRecognizer 这里是焦点处理
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}
4、要良好的前端HTML 编程基础。
5、css中网页图片下方多出几像素问题分析
分析:其实 img 属于 inline 元素,inline 因为受到字号和行间距的影响底部留出了一段距离,距离与字体大小有关,为了解决字母占位不同所导致的问题
那解决办法就很多了,比如:
img {
display: block;
}
或者:
.box {
font-size: 0;
}
把父元素字体为 0 就不会出现占位了,同理 line-height: 0也可以实现。
img {
vertical-align: middle;
}
5、工程代码片段
1》初始化
#pragma mark --- initWithFrame 初始化
-(instancetype)initWithFrame:(CGRect)frame style:(AdvertisementStyle)style{
if (self==[super initWithFrame:frame]) {
_style = style;
self.tag = 1000;
/* 我们添加控件*/
AdvertisementWebView = [[UIWebView alloc]init];
/* 关闭WebView的弹动*/
AdvertisementWebView.scrollView.bounces = NO;
[self addSubview:AdvertisementWebView];
/* 网页添加手势*/
UITapGestureRecognizer * AdvertisementTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(advertisementTapSkipClick)];
AdvertisementTap.delegate = self;
[AdvertisementWebView addGestureRecognizer:AdvertisementTap];
if (style!=FullScreen) {
FoilImageView = [[UIImageView alloc]init];
FoilImageView.userInteractionEnabled = YES;
FoilImageView.contentMode = UIViewContentModeScaleAspectFill;
[self addSubview:FoilImageView];
[self bringSubviewToFront:FoilImageView];
}
UILabel * skipLable = [self skipLabel:6];
[self addSubview:skipLable];
[self bringSubviewToFront:skipLable];
}
return self;
}
2》页面布局
#pragma mark --- layoutSubviews 布局
-(void)layoutSubviews{
/* AdvertisementWebView 布局*/
AdvertisementWebView.frame = self.frame;
if (_style!=FullScreen) {
FoilImageView.frame = CGRectMake(0, self.bounds.size.height*(1-FoilProportion), self.bounds.size.width, self.bounds.size.height * FoilProportion);
}
SkipLable.frame = CGRectMake(self.bounds.size.width-55, 20, 45, 20);
}
3》数据添加
#pragma mark --- addData 添加数据
-(void)addData:(NSDictionary*) transmitDictionary upDataBase:(BOOL) updata{
NSString * path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
/* 获取文件的路径*/
NSString * filePath = [path stringByAppendingString:fileName];
/* 判断文件是否存在*/
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
/* 判断对否更新*/
if (updata) {
/* 移除文件*/
BOOL isRemove = [[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];
if (isRemove) {
[self downloadData:transmitDictionary];
}
}else{
/* 检测文件数据*/
NSDictionary * SizeDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL];
if (SizeDictionary!=nil) {
/* 获取存储数据*/
NSDictionary * infoDictionary = [NSDictionary dictionaryWithContentsOfFile:filePath];
[self loadData:infoDictionary];
}
}
}else{
[self downloadData:transmitDictionary];
}
}
4》数据加载
#pragma mark --- loadData 加载数据
-(void)loadData:(NSDictionary*) loadDataDictionary{
[AdvertisementWebView loadHTMLString:[self createHtml:loadDataDictionary[@"MainWeb"]] baseURL:NULL];
if (_style!=FullScreen) {
FoilImageView.image = [UIImage imageWithData:loadDataDictionary[@"foilImage"]];
}
}
6、工程中的使用
AdvertisementPageView * a = [[AdvertisementPageView alloc]initWithFrame:[UIScreen mainScreen].bounds style:FourPointScreen];
[a addData:@{@"image":@"http://img.dgtle.com/forum/201211/27/1331060codaa1ukeok574y.gif",@"foilimage":@"http://a1.qpic.cn/psb?/V12kpspl0Qwj6m/ec4aSKQl40oed.eYHa*qrrzZgP4kbKBQG8RrumUlRg0!/b/dGgBAAAAAAAA&bo=2gQoAgAAAAADB9Y!&rf=viewer_4"} upDataBase:YES];
[self.window addSubview:a];