引导页

AppDelegate.m

#import "AppDelegate.h"

#import "ViewController.h"

#import "NextViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.next = [[NextViewController alloc]init];

// 判断程序是否第一次打开

NSUserDefaults *TimeOfBootCount = [NSUserDefaults standardUserDefaults];

if (![TimeOfBootCount valueForKey:@"firstLaunch"])

{

[TimeOfBootCount setBool:YES forKey:@"firstLaunch"];

ViewController *v1 = [[ViewController alloc]init];

self.window.rootViewController = v1;

NSLog(@"第一次启动");

}

else

{

NextViewController *next1 = [[NextViewController alloc]init];

self.window.rootViewController = next1;

NSLog(@"不是第一次启动");

}

[self.window makeKeyAndVisible];

NSLog(@"启动成功");

return YES;

}

ViewController.m

#import "ViewController.h"

#import "NextViewController.h

"#import "AppDelegate.h"

@interface ViewController (){

// 创建滚动视图

UIScrollView *theScroll;

// 创建页码视图

UIPageControl *thePage;

// 创建图片的数组

NSArray *theArr;

// 创建整形类

NSInteger teg;

// 创建计时器

NSTimer *theTime;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 获取当前屏幕的宽

float width  = self.view.frame.size.width;

float height = self.view.frame.size.height;

// 初始化滚动视图

theScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];

float X = 0.0;

for (int i =0; i<4; i++)

{

// 创建图片视图

UIImageView *theImg = [[UIImageView alloc]initWithFrame:CGRectMake(X, 0, width, height)];

// 将图片添加带数组中

theArr = @[[UIImage imageNamed:@"IMG1"],[UIImage imageNamed:@"IMG2"],[UIImage imageNamed:@"IMG3"],[UIImage imageNamed:@"IMG4"]];

// 将图片与数据联系

theImg.image = theArr[i];

// 将图片添加到滚动视图上

[theScroll addSubview:theImg];

// X依次递增

X += width;

}

// 设置滚动视图内容大小

theScroll.contentSize = CGSizeMake(width *4, height);

// 设置是否按页滚动

theScroll.pagingEnabled = YES;

// 隐藏滚动条

theScroll.showsHorizontalScrollIndicator = NO;

// 设置代理

theScroll.delegate = self;

// 创建页码

thePage = [[UIPageControl alloc]initWithFrame:CGRectMake(width / 2-50, 570, 100, 30)];

// 清除页码的背景颜色

thePage.backgroundColor = [UIColor clearColor];

// 设置当前页码的颜色

thePage.currentPageIndicatorTintColor = [UIColor blackColor];

// 设置页码的颜色

thePage.pageIndicatorTintColor = [UIColor redColor];

// 设置页码的个数

thePage.numberOfPages = 4;

// 设置页码的起始页码

thePage.currentPage = 0;

// 添加到视图上

// 先添加滚动视图

[self.view addSubview:theScroll];

// 再添加页码视图

[self.view addSubview:thePage];

// 使用整形变量接受页码当前的页码

teg = thePage.currentPage;

// 创建定时器

theTime = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(scroll) userInfo:nil repeats:YES];

}

// 定时器的方法

- (void)scroll

{

teg ++;

if (teg >= theArr.count)

{

teg = 0;

}

// 设置滚动视图的内容偏移量

[theScroll setContentOffset:CGPointMake(teg *self.view.frame.size.width, 0) animated:YES];

}

// 滚动视图的代理方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGPoint point = theScroll.contentOffset;

thePage.currentPage = point.x/scrollView.frame.size.width;

// 创建按钮

UIButton *theBtn = [[UIButton alloc]init];

if (thePage.currentPage == 3)

{

[theTime setFireDate:[NSDate distantFuture]];

// 当滚动到最后一张图片的时候出现按钮

// 设置按钮位置 z

theBtn.frame = CGRectMake(230, 607, 100, 40);

// 设置按钮内容

[theBtn setTitle:@"立即登录" forState:UIControlStateNormal];

// 设置按钮背景颜色

theBtn.backgroundColor = [UIColor redColor];

// 设置按钮响应事件

[theBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

// 添加到视图上 B

[self.view addSubview:theBtn];

}

}

// 按钮方法

- (void)click

{

NextViewController *next = [[NextViewController alloc]init];

AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

app.window.rootViewController = next;

}

NextViewController.m

TableView

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在AppDelegate.m中:我们需要两个Viewcongtroller来实现;myViewController...
    不说谎的匹诺曹Y阅读 322评论 0 0
  • 首先修改 App Transport Security Settings Allow Arbitrary Load...
    Whatever永不放弃阅读 228评论 0 0
  • 每个app都会有引导页, 由于引导页是在第一次启动这个app的时候才会出现, 出于他的这个特点, 我是这样...
    HMZ4978阅读 478评论 0 0
  • 7月28日 周五早晨看了一会儿《JS》,但还是感觉入不了门。今天工作上的事情还很多,而且还有很多简历也没时间去看,...
    hanyu007阅读 161评论 0 1
  • 等手术的时候,或者大失败后,等等外因引起孤独等待的时候,想得多,外延,联系,发散性思维无限延伸。
    zhaodongbo阅读 148评论 0 0