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

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

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

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

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

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

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

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

  1. @interface hDisplayView : UIView

2,.m文件

a,准备

  1. @interface hDisplayView ()
  2. {
  3. NSInteger imgTag;
  4. NSString *picURl;
  5. UIImageView *imageView;
  6. UIImageView *smallImg;
  7. UIButton *timerBtn;
  8.  
  9. int secondsCountDown; //倒计时总时长
  10. NSTimer *countDownTimer;
  11. }
  1. @property(nonatomic,strong)NSFileManager *fileManager;
  2. @property(nonatomic,strong)NSFileHandle *writeHandle;
  3. @property(nonatomic,assign)long long sumLength;
  4. @property(nonatomic,assign)long long currentLength;
  5. @property(nonatomic,strong)UIImage *savedImage;

b,具体实现

  1. @implementation hDisplayView
  2.  
  3. -(instancetype)initWithFrame:(CGRect)frame
  4. {
  5. self = [super initWithFrame:frame];
  6.  
  7. if (self) {
  8. imageView = [[UIImageView alloc]initWithFrame:CGRectMake(, , MainScreen_width, MainScreen_height)];//大背景图片
  9.  
  10. if (IS_IPHONE4 == YES) {
  11. imageView.image = [UIImage imageNamed:@"start_ios-1"];
  12. }else
  13. {
  14. imageView.image = [UIImage imageNamed:@"start_ios"];
  15. }
  16.  
  17. imageView.userInteractionEnabled = YES;
  18. [self addSubview:imageView];
  19.  
  20. smallImg = [[UIImageView alloc]initWithFrame:CGRectMake(, , MainScreen_width, MainScreen_height-)];
  21. // smallImg.image = [UIImage imageNamed:@"start-ad"];
  22. [imageView addSubview:smallImg];
  23.  
  24. timerBtn = [[UIButton alloc]initWithFrame:CGRectMake(MainScreen_width - - , , , )];
  25.  
  26. [self initView];
  27. }
  28. return self;
  29. }
  30.  
  31. -(void)initBtn
  32. {
  33.  
  34. timerBtn.clipsToBounds = YES;
  35. timerBtn.layer.cornerRadius = ;
  36. [timerBtn setTitleColor:RGB(, , ) forState:UIControlStateNormal];
  37. timerBtn.titleLabel.font = [UIFont systemFontOfSize:];
  38. [timerBtn addTarget:self action:@selector(jumpBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  39. [imageView addSubview:timerBtn];
  40. timerBtn.titleLabel.numberOfLines = ;
  41. timerBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
  42. timerBtn.backgroundColor = RGBA(, , , 0.5);
  43.  
  44. //开始倒计时
  45. countDownTimer = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; //启动倒计时后会每秒钟调用一次方法 timeFireMethod
  46. [[NSRunLoop mainRunLoop] addTimer:countDownTimer forMode:NSDefaultRunLoopMode];
  47.  
  48. //[NSThread detachNewThreadSelector:@selector(starTimer) toTarget:self withObject:nil];
  49.  
  50. //设置倒计时显示的时间
  51. //设置倒计时总时长
  52. secondsCountDown = ;//60秒倒计时
  53. [timerBtn setTitle:[NSString stringWithFormat:@"跳过\n%ds",secondsCountDown] forState:UIControlStateNormal];
  54.  
  55. // NSTimeInterval period = 1.0; //设置时间间隔
  56. // dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  57. // dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
  58. // dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), period * NSEC_PER_SEC, 0); //每秒执行
  59. // dispatch_source_set_event_handler(_timer, ^{
  60. // //在这里执行事件
  61. // if (secondsCountDown<=0) {
  62. // dispatch_source_cancel(_timer);
  63. // dispatch_async(dispatch_get_main_queue(), ^{
  64. // self.hidden = YES;
  65. // });
  66. //
  67. // }else{
  68. // dispatch_async(dispatch_get_main_queue(), ^{
  69. //
  70. // if (secondsCountDown==0) {
  71. // self.hidden = YES;
  72. // }else{
  73. // [timerBtn setTitle:[NSString stringWithFormat:@"跳过\n%ds",secondsCountDown] forState:UIControlStateNormal];
  74. // }
  75. // });
  76. // secondsCountDown--;
  77. // }
  78. // NSLog(@"循环执行");
  79. // //[self timeFireMethod];
  80. // });
  81. // dispatch_resume(_timer);
  82.  
  83. }
  84.  
  85. -(void)initView
  86. {
  87. //先进行判断,1:如果是第一次启动不显示此启动图片,2:如果不是第一次启动,那么加载此启动图片,如果图片不存在就下载,如果图片存在就读取缓存
  88. hUser *huser = [[hUser alloc]init];
  89. [hHttpEngine getStartupPicRequest:huser success:^(id response) {
  90. NSLog(@"respons ----%@",response);
  91. NSDictionary *dict = (NSDictionary *)response;
  92. NSString *stautes = [NSString stringWithFormat:@"%@",[dict objectForKey:@"status"]];
  93. if ([stautes isEqualToString:@""]) {
  94. picURl = [NSString stringWithFormat:@"%@",[dict objectForKey:@"pic"]];
  95. NSLog(@"picurl is %@",picURl);
  96. [smallImg sd_setImageWithURL:[NSURL URLWithString:picURl] placeholderImage:[UIImage imageNamed:@""]];
  97. smallImg.userInteractionEnabled = YES;
  98. [self initBtn];
  99. }
  100. }failure:^(NSError *err) {
  101. self.hidden = YES;
  102. }];
  103.  
  104. }
  105.  
  106. -(void)jumpBtnClick:(id)sender
  107. {
  108. self.hidden = YES;
  109. }
  110.  
  111. -(void)timeFireMethod{
  112.  
  113. //倒计时-1
  114. secondsCountDown--;
  115. //修改倒计时标签现实内容
  116. [timerBtn setTitle:[NSString stringWithFormat:@"跳过\n%ds",secondsCountDown] forState:UIControlStateNormal];
  117.  
  118. //当倒计时到0时,做需要的操作,比如验证码过期不能提交
  119. if(secondsCountDown==){
  120. [countDownTimer invalidate];
  121. self.hidden = YES;
  122. }
  123. }
  124.  
  125. @end

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

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

  1. hDisplayView *hVC = [[hDisplayView alloc] initWithFrame:CGRectMake(, , MainScreen_width, MainScreen_height)];
  2. hVC.hidden = NO;
  3. [self.window.rootViewController.view addSubview:hVC];
  4. [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. gulp入门与一些基本设置

    这里是gulp入门的一些操作,实现了编译sass文件.压缩.合并.添加版本号等基本功能. 友情提示,如果npm出现无法下载可以安装 cnpm.在安装完Nodejs 后 npm install cnpm ...

  2. [转]采购文件中 RFI、RFQ、RFP、IFB的区别

    原文:http://www.douban.com/group/topic/23426427/ [PMBOK的描述]  采购文件用于征求潜在卖方的建议书.如果主要依据价格来选择卖方(如购买商业或标准产品 ...

  3. Android开发日记(五)

    从服务器端传递多个数据 先在服务器端设置cs文件 using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using Syst ...

  4. RTX——第17章 定时器组

    以下内容转载自安富莱电子: http://forum.armfly.com/forum.php 本章节为大家讲解 RTX 支持的定时器组,或者叫软件定时器,或者叫用户定时器均可.软件定时器的功能比较简 ...

  5. javascript 中 IE与FF的不同之处及其兼容写法

    png透明 AlphaImageLoaderfilter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=bEnabled,siz ...

  6. Oracle PL/SQL 编程基础 实例

    create table mytest(name varchar(20),password varchar(30)); create or replace procedure sp_pro2 is  ...

  7. pthread_join直接决定资源是否能够及时释放

    /*http://hankjin.blog.163.com/blog/static/33731937201072675024100/ pthread的内存泄露 # cc thread.c -lpthr ...

  8. Android——适配器其他组件(AutoCompleteTextView:自动完成文本编辑框;Spinner:下拉列表)

    activity_activitywenben.xml <?xml version="1.0" encoding="utf-8"?> <Lin ...

  9. protobuf--数据序列化及反序列化

    ProtoBuf是一种灵活高效的独立于语言平台的结构化数据表示方法,可用于表示通信协议和数据存储等各方面,与XML相比,ProtoBuF更小更快更简单.你可以用定义自己ProtoBuf的数据结构,用P ...

  10. Spring下获取项目根路径--good

    Spring 在 org.springframework.web.util 包中提供了几个特殊用途的 Servlet 监听器,正确地使用它们可以完成一些特定需求的功能.比如某些第三方工具支持通过 ${ ...