1. 新建两个视图控制器类(继承自UIViewController), 在AppDelegate.m中指定根视图控制器

  1. #import "AppDelegate.h"
  2. #import "RootViewController.h"
  3. #import "LeadViewController.h"
  4. @interface AppDelegate ()
  5.  
  6. @end
  7.  
  8. @implementation AppDelegate
  9.  
  10. - (void)dealloc
  11. {
  12. self.window = nil;
  13. [super dealloc];
  14. }
  15.  
  16. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  17. self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
  18. // Override point for customization after application launch.
  19. self.window.backgroundColor = [UIColor whiteColor];
  20. [self.window makeKeyAndVisible];
  21.  
  22. // 在用户的偏好设置中做标记,判断用户是否是第一次打开应用
  23. // [NSUserDefaults standardUserDefaults]; // 获取用户的偏好设置选项
  24. BOOL isFirst = [[NSUserDefaults standardUserDefaults] boolForKey:@"NB"];
  25. NSLog(@"isFirst = %d", isFirst); // 第一次打印为0 ,第二次打印为1
  26. if (isFirst) {// 若为真,直接进入应用
  27.  
  28. RootViewController *rootVC = [[RootViewController alloc] init];
  29. self.window.rootViewController = rootVC;
  30. [rootVC release];
  31.  
  32. } else { // 若为假,启动引导页
  33.  
  34. LeadViewController *leadVC = [[LeadViewController alloc] init];
  35. self.window.rootViewController = leadVC;
  36. [leadVC release];
  37.  
  38. }
  39.  
  40. return YES;
  41. }

2. 在LeadViewController中写主要代码

  1. //
  2. // LeadViewController.m
  3.  
  4. /**
  5. * 引导页面制作
  6. *
  7. */
  8.  
  9. #import "LeadViewController.h"
  10.  
  11. #import "RootViewController.h"
  12.  
  13. #define kScreenWidth [UIScreen mainScreen].bounds.size.width
  14. #define kScreenHeight [UIScreen mainScreen].bounds.size.height
  15. #define kImageCount 6
  16. @interface LeadViewController ()<UIScrollViewDelegate>
  17. @property (nonatomic, retain) UIPageControl *pageControl;
  18. @property (nonatomic, retain) UIScrollView *scrollView;
  19. @end
  20.  
  21. @implementation LeadViewController
  22.  
  23. - (void)dealloc
  24. {
  25. self.pageControl = nil;
  26. self.scrollView = nil;
  27. [super dealloc];
  28. }
  29.  
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. //self.view.backgroundColor = [UIColor redColor];
  33.  
  34. [self configureScrollView];
  35.  
  36. [self configurePageControl]; //! 先调用这个方法的话,后来的scrollView就会把pageControl给盖住
  37.  
  38. }
  39. // 配置滚动视图
  40. - (void)configureScrollView {
  41.  
  42. self.scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  43. _scrollView.backgroundColor = [UIColor yellowColor];
  44. // 内容区域大小
  45. _scrollView.contentSize = CGSizeMake(kImageCount * kScreenWidth, kScreenHeight); // 内容区域宽度为图片个数*屏幕宽度
  46. [self.view addSubview:_scrollView];
  47. [_scrollView release];
  48.  
  49. // 向_scrollView上添加imageView对象
  50. for (int i = 0; i < kImageCount; i++) {
  51. // 准备图片
  52. UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"v6_guide_%d", i+1]];
  53. // 创建UIImageView对象
  54. UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  55. // 设置frame
  56. imageView.frame = CGRectMake(kScreenWidth * i, 0, kScreenWidth, kScreenHeight); //!
  57.  
  58. //! 让_scrollView整页滑动
  59. _scrollView.pagingEnabled = YES;
  60. //! 关闭弹簧效果
  61. _scrollView.bounces = NO;
  62.  
  63. _scrollView.delegate = self; // 添加代理,处理事件
  64.  
  65. [_scrollView addSubview:imageView];
  66.  
  67. [imageView release];
  68.  
  69. // 最后一张图片添加轻拍手势
  70. if (5 == i) {
  71.  
  72. imageView.userInteractionEnabled = YES; //!UIlabel和UIimageView的默认交互是关的
  73.  
  74. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
  75.  
  76. [imageView addGestureRecognizer:tap];// 手势添加到imageView上
  77.  
  78. [tap release];
  79.  
  80. }
  81. }
  82.  
  83. }
  84.  
  85. // 实现手势关联的事件
  86. - (void)handleTap:(UITapGestureRecognizer *)tap {
  87. // 设置用户的偏好设置
  88. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"NB"];
  89. // 更改应用window的根视图控制器
  90. // [UIApplication sharedApplication] 取出当前应用对象
  91. RootViewController *rootVC = [[RootViewController alloc]init];
  92.  
  93. [UIApplication sharedApplication].keyWindow.rootViewController = rootVC; // 这个window和AppDelegate.m中的window是一个window
  94.  
  95. [rootVC release];
  96.  
  97. }
  98. // 配置分页控制器
  99. - (void)configurePageControl {
  100. self.pageControl = [[UIPageControl alloc] initWithFrame:(CGRectMake(0, kScreenHeight - 40, kScreenWidth, 30))];// 在屏幕下方添加pageContro
  101. //_pageControl.backgroundColor = [UIColor blackColor];
  102. // 分页个数
  103. _pageControl.numberOfPages = kImageCount;
  104. // 当前点的颜色
  105. _pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
  106. // 其他点的颜色
  107. _pageControl.pageIndicatorTintColor = [UIColor yellowColor];
  108. // 添加关联事件
  109. [_pageControl addTarget:self action:@selector(handlePageControl:) forControlEvents:(UIControlEventValueChanged)];
  110. // 添加到视图控制器上
  111. [self.view addSubview:_pageControl];
  112. [_pageControl release];
  113.  
  114. }
  115. #pragma maek - 实现代理方法(协议中的方法)
  116. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  117. // 减速结束时取出偏移量
  118. CGPoint offSet = scrollView.contentOffset;
  119. CGFloat number = offSet.x / kScreenWidth;
  120. _pageControl.currentPage = (NSInteger)number; // image与点关联 scrollView 与 pageControl关联
  121. }
  122.  
  123. // 实现分页控制器关联的方法
  124. - (void)handlePageControl:(UIPageControl *)sender {
  125. // 取出当前分页
  126. NSInteger number = sender.currentPage;
  127. // 通过分页控制scrollView的偏移量
  128. _scrollView.contentOffset = CGPointMake(number * kScreenWidth, 0); // 点与image关联 pageControl 与 scrollView关联
  129. }
  130.  
  131. - (void)didReceiveMemoryWarning {
  132. [super didReceiveMemoryWarning];
  133. // Dispose of any resources that can be recreated.
  134. }
  135.  
  136. @end

UIPageControl和UIScrollView这两种UI控件的结合使用,很常见,APP第一次打开时的引导界面用这两个控件就可以完成了~

使用UIPageControl UIScrollView制作APP引导界面的更多相关文章

  1. App 引导界面

    App 引导界面 1.前言 最近在学习实现App的引导界面,本篇文章对设计流程及需要注意的地方做一个浅显的总结. 附上项目链接,供和我水平类似的初学者参考——http://files.cnblogs. ...

  2. App引导界面,可以这么玩

    什么是ViewPager,刚一听到这个词,我们可能感觉很奇怪,但是我相信我们大部分人都曾见到过这些界面的.其实它就是我们在安装好一个app之后第一次使用时的那些引导界面的效果.这就是通过ViewPag ...

  3. 用PS制作APP的界面图片

    今天就教大家怎么做出这种厚度的地方还不是白色的,而是根据界面内容交相呼应的图案的APP界面展示图片. 以苹果5S的尺寸为例. 步骤: 1.新建一个画布尺寸为:640*1136,然后保存,命名如:5S效 ...

  4. Android--ViewPager制作APP引导页

    ViewPager使用FragmentStatePagerAdapter做Adapter,引导页使用多Fragment形式. FragmentStatePagerAdapter代码如下: public ...

  5. ViewPager制作APP引导页+若干动画效果

    ViewPager使用FragmentStatePagerAdapter做Adapter,引导页使用多Fragment形式. 见http://www.cnblogs.com/bmbh/p/567276 ...

  6. Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面

    Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面 关于欢迎界面 很多App第一次启动都会有一个欢迎界面,欢迎界面往往决定这用户对App的第一映像,所以欢 ...

  7. IOS炫酷的引导界面

    代码地址如下:http://www.demodashi.com/demo/11246.html 一.准备工作 1.先用时ps工具制作好图片 2.然后计算好每张图片通过滑动视图的偏移量来改变图片的位置 ...

  8. Hybrid App技术批量制作APP应用与跨平台解决方案

    前言 简单的聊一聊我开发了4年之久的Hybrid App(混合模式移动应用)平台开发,目前一直在持续开发与维护,支持无编程快速开发! 其本意也不是要吹捧前端有多么强大,只是用自己的实际项目阐述下对于前 ...

  9. 【笔记】WPF实现ViewPager引导界面效果及问题汇总

    最近在开发项目的首次使用引导界面时,遇到了问题,引导界面类似于安卓手机ViewPager那样的效果,希望通过左右滑动手指来实现切换不同页面,其间伴随动画. 实现思路: 1.界面布局:新建一个UserC ...

随机推荐

  1. Oracle错误问题---- 《ora-12638:身份证明检索失败》

    使用客户端可以连接,但只有一个站点出现此问题,非常郁闷,网上查了一下,发现是用户认证问题,解决办法如下: 在ORACLE客户端目录下 NETWORK/ADMIN下的sqlnet.ora,使用记事本打开 ...

  2. 设置CentOS里的Mysql开启客户端远程连接

    CentOS系统安装好MySQL后,默认情况下不支持用户通过非本机连接上数据库服务器,下面是解决方法: 1.在控制台执行 mysql -u root -p mysql,系统提示输入数据库root用户的 ...

  3. JS函数定义与匿名函数的调用

    一.函数声明.函数表达式.匿名函数 函数声明:function fnName () {…};使用function关键字 声明一个函数,再指定一个函数名,叫函数声明. 函数表达式 var fnName ...

  4. NGUI类之间的关系和架构

    NGUI Drawcall 1.使用同一个altals的元素尽量放在同一个UIPanel下面,在NGUI中,它消耗的drawcall是以每个Panel为独立计算单位进行计算的. 2.如果一个UIPan ...

  5. 一个坑:java.sql.ResultSet.getInt==》the column value; if the value is SQL NULL, the value returned is 0

    Retrieves the value of the designated column in the current row of this ResultSet object as a String ...

  6. buffer busy wait

    什么是buffer busy wait? A session that reads or modifies a buffer in the SGA must first acquire the cac ...

  7. 【HDOJ】3184 All Can Do

    简单数学题. #include <cstdio> #include <cstring> #include <cstdlib> int main() { int t; ...

  8. Android中ListView通过BaseAdapter实现数据的绑定

    1. public class ListFiles extends Activity { ListView Listview=null; protected void onCreate(Bundle ...

  9. HDU_2047——EOF字符串排序排列问题,递推

    Problem Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的友 ...

  10. URAL 2034 : Caravans

    Description   Student Ilya often skips his classes at the university. His friends criticize him for ...