以往在写启动页面的时候,有时候会直接在启动页里面写,或者自带的vc里面直接写,但是那样并不是很方便,启动页里面往往会添加很多的东西,所以封装成一个单独的类,可以直接使用,即便是后期的更换,或者是其他的工程项目里面需要,直接拖过去,就可以直接使用非常方便!

具体代码就不上传了,附demo的下载地址:

https://github.com/hgl753951/launchTest.git

早先在cocoachina上上传的一个demo:

http://code.cocoachina.com/view/131777

比较简单,可以直接下载demo来看!

下面写一个带有倒计时的广告页功能:

1,新创建一个集成于UIView的类:

@interface hDisplayView : UIView

2,.m文件

a,准备

@interface hDisplayView ()
{
NSInteger imgTag;
NSString *picURl;
UIImageView *imageView;
UIImageView *smallImg;
UIButton *timerBtn; int secondsCountDown; //倒计时总时长
NSTimer *countDownTimer;
}
@property(nonatomic,strong)NSFileManager *fileManager;
@property(nonatomic,strong)NSFileHandle *writeHandle;
@property(nonatomic,assign)long long sumLength;
@property(nonatomic,assign)long long currentLength;
@property(nonatomic,strong)UIImage *savedImage;

b,具体实现

@implementation hDisplayView

-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame]; if (self) {
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(, , MainScreen_width, MainScreen_height)];//大背景图片 if (IS_IPHONE4 == YES) {
imageView.image = [UIImage imageNamed:@"start_ios-1"];
}else
{
imageView.image = [UIImage imageNamed:@"start_ios"];
} imageView.userInteractionEnabled = YES;
[self addSubview:imageView]; smallImg = [[UIImageView alloc]initWithFrame:CGRectMake(, , MainScreen_width, MainScreen_height-)];
// smallImg.image = [UIImage imageNamed:@"start-ad"];
[imageView addSubview:smallImg]; timerBtn = [[UIButton alloc]initWithFrame:CGRectMake(MainScreen_width - - , , , )]; [self initView];
}
return self;
} -(void)initBtn
{ timerBtn.clipsToBounds = YES;
timerBtn.layer.cornerRadius = ;
[timerBtn setTitleColor:RGB(, , ) forState:UIControlStateNormal];
timerBtn.titleLabel.font = [UIFont systemFontOfSize:];
[timerBtn addTarget:self action:@selector(jumpBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:timerBtn];
timerBtn.titleLabel.numberOfLines = ;
timerBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
timerBtn.backgroundColor = RGBA(, , , 0.5); //开始倒计时
countDownTimer = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; //启动倒计时后会每秒钟调用一次方法 timeFireMethod
[[NSRunLoop mainRunLoop] addTimer:countDownTimer forMode:NSDefaultRunLoopMode]; //[NSThread detachNewThreadSelector:@selector(starTimer) toTarget:self withObject:nil]; //设置倒计时显示的时间
//设置倒计时总时长
secondsCountDown = ;//60秒倒计时
[timerBtn setTitle:[NSString stringWithFormat:@"跳过\n%ds",secondsCountDown] forState:UIControlStateNormal]; // NSTimeInterval period = 1.0; //设置时间间隔
// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
// dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
// dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行
// dispatch_source_set_event_handler(_timer, ^{
// //在这里执行事件
// if (secondsCountDown<=0) {
// dispatch_source_cancel(_timer);
// dispatch_async(dispatch_get_main_queue(), ^{
// self.hidden = YES;
// });
//
// }else{
// dispatch_async(dispatch_get_main_queue(), ^{
//
// if (secondsCountDown==0) {
// self.hidden = YES;
// }else{
// [timerBtn setTitle:[NSString stringWithFormat:@"跳过\n%ds",secondsCountDown] forState:UIControlStateNormal];
// }
// });
// secondsCountDown--;
// }
// NSLog(@"循环执行");
// //[self timeFireMethod];
// });
// dispatch_resume(_timer); } -(void)initView
{
//先进行判断,1:如果是第一次启动不显示此启动图片,2:如果不是第一次启动,那么加载此启动图片,如果图片不存在就下载,如果图片存在就读取缓存
hUser *huser = [[hUser alloc]init];
[hHttpEngine getStartupPicRequest:huser success:^(id response) {
NSLog(@"respons ----%@",response);
NSDictionary *dict = (NSDictionary *)response;
NSString *stautes = [NSString stringWithFormat:@"%@",[dict objectForKey:@"status"]];
if ([stautes isEqualToString:@""]) {
picURl = [NSString stringWithFormat:@"%@",[dict objectForKey:@"pic"]];
NSLog(@"picurl is %@",picURl);
[smallImg sd_setImageWithURL:[NSURL URLWithString:picURl] placeholderImage:[UIImage imageNamed:@""]];
smallImg.userInteractionEnabled = YES;
[self initBtn];
}
}failure:^(NSError *err) {
self.hidden = YES;
}]; } -(void)jumpBtnClick:(id)sender
{
self.hidden = YES;
} -(void)timeFireMethod{ //倒计时-1
secondsCountDown--;
//修改倒计时标签现实内容
[timerBtn setTitle:[NSString stringWithFormat:@"跳过\n%ds",secondsCountDown] forState:UIControlStateNormal]; //当倒计时到0时,做需要的操作,比如验证码过期不能提交
if(secondsCountDown==){
[countDownTimer invalidate];
self.hidden = YES;
}
} @end

具体效果就不上传了,可以直接复制上面的代码,自行运行查看效果;

c,在AppDelegate里面添加,就是给当前window添加一个根视图:

    hDisplayView *hVC = [[hDisplayView alloc] initWithFrame:CGRectMake(, , MainScreen_width,  MainScreen_height)];
hVC.hidden = NO;
[self.window.rootViewController.view addSubview:hVC];
[self.window bringSubviewToFront:hVC];

搞定,这两个效果可以结合用,判断第一次运行app,引导页出现,反之则出现广告业!

ios开发之--新手引导页的添加的更多相关文章

  1. ios开发之--新手引导页图片适配方案

    1,图片适配,最早以前是自己命名规范,例如@1x,@2x,@3x等,3套图基本上就够用了 2,在iPhone X之后,需要适配的图就多了,因为分辨率增多了,屏幕尺寸也增多了 3,尺寸 :640*960 ...

  2. 在iOS开发中,给项目添加新的.framework

    首先需要了解一下iOS中静态库和动态库.framework的概念 静态库与动态库的区别 首先来看什么是库,库(Library)说白了就是一段编译好的二进制代码,加上头文件就可以供别人使用. 什么时候我 ...

  3. IOS开发效率之为Xcode添加常用的代码片段

    IOS开发效率之为Xcode添加常用的代码片段 原文地址:http://blog.csdn.net/pingchangtan367/article/details/30041285 tableview ...

  4. iOS开发 关于启动页和停留时间的设置

    引言: 在开发一款商业App时,我们大都会为我们的App设置一个启动页. 苹果官方对于iOS启动页的设计说明: 为了增强应用程序启动时的用户体验,您应该提供一个启动图像.启动图像与应用程序的首屏幕看起 ...

  5. iOS开发-在表单元中添加子视图

    #import <UIKit/UIKit.h> @interface NameAndColorCellTableViewCell : UITableViewCell @property(c ...

  6. iOS开发中在UIWebView中添加Gif动态图

    开发是一件很有趣的事,偶尔在程序中添加一些小东西,会给你的应用增色不少.比如,当你的某些功能暂时还不准备上线时,可以先一个放展示Gif动态图的UIWebView上去,既可以告诉用户APP以后会有的功能 ...

  7. iOS开发:为xcode项目添加git仓储

    现在apple官网下载Command Line Tools 对应mac版本和xcode版本,记录地址:https://developer.apple.com/downloads/ 找到mac的终端,c ...

  8. IOS开发中如何给UIImageView添加点击事件

    1.先创建一个UIImageView控件: photeImageView = [[UIImageView alloc]init]; photeImageView.frame = CGRectMake( ...

  9. iOS开发之--为PCH文件添加绝对路径

    要想设置PCH的相对路径,首先我们需要去查看绝对路径. 相对路径 点击PCH文件,Xcode的右侧会显示PCH的属性.这里我们可以获取到PCH的绝对路径.从工程的路径开始,前面使用$(SRCROOT) ...

随机推荐

  1. AAuto 快速开发win32小程序

    AAuto编程语言 AAuto是专用于桌面软件快速开发的新一代混合型编程语言 -  具有动态语言轻便.灵活.快速开发的特性,而且又可以同时支持静态类型开发,象静态语言那样使用.AAuto可以直接支持原 ...

  2. 基于python的接口测试框架设计(三)接口测试的框架

    基于python的接口测试框架设计(三)接口测试的框架 其实我这里用到的是unittest单元测试框架,,这个框架好就好在比较清楚,,setup terdown都可以处理一些初始化及完成后的工作 主要 ...

  3. C#通过“委托和事件”的方式实现进程监控并与“普通方式”对比

    今天重新学习了一下观察者模式,对我的思路产生了启发.进程监控程序之前写过几个,这回换一种思路,改用委托和事件来实现.我已经用序号将关键的几步标注,方便大家理顺思路.代码如下: using System ...

  4. RTX——第9章 任务运行在特权级或非特权级模式

    以下内容转载自安富莱电子: http://forum.armfly.com/forum.php 本章教程为大家讲解 RTX 运行模式的一个重要知识点,特权级模式和非特权级模式,有些资料或者书籍将非特权 ...

  5. 【Unity笔记】UGUI的自动布局功能

    一些RectTransform的物体(UGUI元素)已经实现了ILayoutElement接口,如Image. 如果一个RectTransform的物体(UGUI元素)的其中一个组件实现了ILayou ...

  6. Java并发(零)教程目录

    上网看博客的时候无意中发现了有一个Java并发的教程还不错,有20多篇讲并发的,一天翻译1篇似乎也不太难.Let's go! 原文地址:http://tutorials.jenkov.com/java ...

  7. JavaScrip——练习(做悬浮框)

    通过HTML.CSS.JSP来实现 1.首先确定通过div嵌套来实现: 大的div里放默认显示的一层,限制其总层次高,设置超出部分隐藏 小的div里放鼠标移过去时显示的一层:3行1列的表格 1.1.什 ...

  8. Oracle分页(limit方式的运用)

    select * from a_matrix_navigation_map where rowid not in(select rowid from a_matrix_navigation_map w ...

  9. LintCode - Copy List with Random Pointer

    LintCode - Copy List with Random Pointer LintCode - Copy List with Random Pointer Web Link Descripti ...

  10. server后台程序的内存使用问题

    眼下我开发的一个server后台程序存在这么一个问题,因为我的程序要不断的收发消息,并做统计.统计用的是stl的多重map.在统计中会不断的往map里赛数据. 可是每次统计后我都会调用clear()去 ...