iOS 引导页
2016-07-04 00:00
375 查看
摘要: 目前多数app在启动时会有引导页,今天给大家介绍一种比较直观,能够快速实现的引导页实现方法,最终效果就是有一个全屏的引导页(UIScrollView),页面底部有UIPageControl。
/**
承载引导页的控制器,主页面HomePageViewController.h
*/
#import "UserGuideViewController.h"
#import "HomePageViewController.h"
#define K_MainScreen_width [UIScreen mainScreen].bounds.size.width
#define K_MainScreen_height [UIScreen mainScreen].bounds.size.height
@interface UserGuideViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong)UIPageControl *pageControl;
@end
@implementation UserGuideViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
[self initGuide];
}
#pragma mark - 初始化引导页;
- (void)initGuide{
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,K_MainScreen_width , K_MainScreen_height)];
// 设置滑动的范围,3 倍的屏幕,Y为0 横向滑动
[scrollView setContentSize:CGSizeMake(3 * K_MainScreen_width, 0)];
scrollView.delegate = self;
// 整页滑动
scrollView.pagingEnabled = YES;
// 禁止回弹,防止漏出根视图
scrollView.bounces = NO;
[self.view addSubview:scrollView];
// pageControll
_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(K_MainScreen_width/3, K_MainScreen_height/3 * 2 + 50, K_MainScreen_width/3, 10)];
_pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
_pageControl.pageIndicatorTintColor = [UIColor greenColor];
_pageControl.numberOfPages = 3;
_pageControl.currentPage = 0;
[self.view addSubview:_pageControl];
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, K_MainScreen_width, K_MainScreen_height)];
imageView1.image = [UIImage imageNamed:@"3196253_091326185000_2.jpg"];
[scrollView addSubview:imageView1];
UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(K_MainScreen_width, 0, K_MainScreen_width, K_MainScreen_height)];
imageView2.image = [UIImage imageNamed:@"20140531221642_uyhvL.jpg"];
[scrollView addSubview:imageView2];
UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(2 * K_MainScreen_width, 0, K_MainScreen_width, K_MainScreen_height)];
imageView3.image = [UIImage imageNamed:@"3167975_143302780126_2.jpg"];
[scrollView addSubview:imageView3];
// 开始按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(K_MainScreen_width/3, K_MainScreen_height/3 * 2, K_MainScreen_width/3, 40);
[button setTitle:@"开始进入" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonJOIN:) forControlEvents:UIControlEventTouchUpInside];
imageView3.userInteractionEnabled = YES;
[imageView3 addSubview:button];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
_pageControl.currentPage =scrollView.contentOffset.x/ K_MainScreen_width;
}
- (void)buttonJOIN:(UIButton *)sender{
HomePageViewController *homePage = [[HomePageViewController alloc]init];
UINavigationController *NaVC = [[UINavigationController alloc]initWithRootViewController:homePage];
[UIApplication sharedApplication].keyWindow.rootViewController = NaVC;
}
/**
AppDelegate.h中判断是否第一次启动。
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// 判断是否是第一次启动应用
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
NSLog(@"这是第一次启动,添加引导页");
UserGuideViewController *userGuideVC = [[UserGuideViewController alloc]init];
self.window.rootViewController = userGuideVC;
}else {
HomePageViewController *homePage = [[HomePageViewController alloc]init];
UINavigationController *NaVC = [[UINavigationController alloc]initWithRootViewController:homePage];
self.window.rootViewController = NaVC;
}
return YES;
}
/**
承载引导页的控制器,主页面HomePageViewController.h
*/
#import "UserGuideViewController.h"
#import "HomePageViewController.h"
#define K_MainScreen_width [UIScreen mainScreen].bounds.size.width
#define K_MainScreen_height [UIScreen mainScreen].bounds.size.height
@interface UserGuideViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong)UIPageControl *pageControl;
@end
@implementation UserGuideViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
[self initGuide];
}
#pragma mark - 初始化引导页;
- (void)initGuide{
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,K_MainScreen_width , K_MainScreen_height)];
// 设置滑动的范围,3 倍的屏幕,Y为0 横向滑动
[scrollView setContentSize:CGSizeMake(3 * K_MainScreen_width, 0)];
scrollView.delegate = self;
// 整页滑动
scrollView.pagingEnabled = YES;
// 禁止回弹,防止漏出根视图
scrollView.bounces = NO;
[self.view addSubview:scrollView];
// pageControll
_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(K_MainScreen_width/3, K_MainScreen_height/3 * 2 + 50, K_MainScreen_width/3, 10)];
_pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
_pageControl.pageIndicatorTintColor = [UIColor greenColor];
_pageControl.numberOfPages = 3;
_pageControl.currentPage = 0;
[self.view addSubview:_pageControl];
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, K_MainScreen_width, K_MainScreen_height)];
imageView1.image = [UIImage imageNamed:@"3196253_091326185000_2.jpg"];
[scrollView addSubview:imageView1];
UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(K_MainScreen_width, 0, K_MainScreen_width, K_MainScreen_height)];
imageView2.image = [UIImage imageNamed:@"20140531221642_uyhvL.jpg"];
[scrollView addSubview:imageView2];
UIImageView *imageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(2 * K_MainScreen_width, 0, K_MainScreen_width, K_MainScreen_height)];
imageView3.image = [UIImage imageNamed:@"3167975_143302780126_2.jpg"];
[scrollView addSubview:imageView3];
// 开始按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(K_MainScreen_width/3, K_MainScreen_height/3 * 2, K_MainScreen_width/3, 40);
[button setTitle:@"开始进入" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonJOIN:) forControlEvents:UIControlEventTouchUpInside];
imageView3.userInteractionEnabled = YES;
[imageView3 addSubview:button];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
_pageControl.currentPage =scrollView.contentOffset.x/ K_MainScreen_width;
}
- (void)buttonJOIN:(UIButton *)sender{
HomePageViewController *homePage = [[HomePageViewController alloc]init];
UINavigationController *NaVC = [[UINavigationController alloc]initWithRootViewController:homePage];
[UIApplication sharedApplication].keyWindow.rootViewController = NaVC;
}
/**
AppDelegate.h中判断是否第一次启动。
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// 判断是否是第一次启动应用
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
NSLog(@"这是第一次启动,添加引导页");
UserGuideViewController *userGuideVC = [[UserGuideViewController alloc]init];
self.window.rootViewController = userGuideVC;
}else {
HomePageViewController *homePage = [[HomePageViewController alloc]init];
UINavigationController *NaVC = [[UINavigationController alloc]initWithRootViewController:homePage];
self.window.rootViewController = NaVC;
}
return YES;
}
相关文章推荐
- iOS10开发
- 漫谈安卓和ios,mac os x
- 记录一下iOS开发中琐碎的点点_4
- iOS画板实现第二波
- iOS图层layer操作
- iOS中表单视图第三方控件——FXForms
- iOS NSURL、NSBundle获取文件,解析文件,存储文件等操作
- iOS中定位以及地图的使用
- Xamarin.iOS开发初体验
- iOS中,ARC的环境下的单例模式。
- 在iOS开发中,需要用到的多线程技术。
- 关于iOS中的手势识别
- iOS开发的22个奇葩技巧
- ios推送相关资料整理
- GCD
- iOS Foundation 基础框架
- 重定向 NSLog 输出到文件
- iOS 开发中的各种证书
- iOS 使用Charts框架 折线,柱状,K线,饼状,雷达全攻略
- 欢迎使用CSDN-markdown编辑器