UI:UIScrollView、UIPageControl

一、UIScrollView的常⽤用属性

二、UIScrollView的常⽤用代理方法

三、UIPageControl的使⽤用

四、UIPageControl与UIScrollView的结合使⽤用

UIScrollView是可以滚动的view,UIView本⾝身不能滚动,是UIView的子类

UIScrollview拓展了滚动⽅方⾯面的功能。 UIScrollView是所有滚动视图的基类。UITableView,UITextView等视图都是继承于该类。

使⽤用场景:显⽰示不下(单张⼤大图);内容太多(图⽂文混排);滚动头条(图⽚片);相册等

UIScrollview主要专⻓长于两个方⾯:

滚动:contentSize⼤大于frame.size的时候,能够滚动。 缩放:⾃自带缩放,可以指定缩放倍数。

contentSize //定义内容区域⼤小,决定是否能够滑动

contentOffset //视图左上⾓角距离坐标原点的偏移量

scrollsToTop //滑动到顶部(点状态条的时候)

pagingEnabled //是否整屏翻动

bounces //边界是否回弹

scrollEnabled //是否能够滚动

showsHorizontalScrollIndicator //控制是否显⽰示⽔水平⽅方向的滚动条

showVerticalScrollIndicator   //控制是否显⽰示垂直⽅方向的滚动条

alwaysBounceVertical   //控制垂直⽅方向遇到边框是否反弹

alwaysBounceHorizontal  //控制⽔水平⽅方向遇到边框是否反弹

minimumZoomScale // 缩⼩小的最⼩小⽐比例

maximumZoomScale //放⼤大的最⼤大⽐比例

zoomScale //设置变化⽐比例

zooming //判断是否正在进⾏行缩放反弹

bouncesZoom
要实现缩放,还需要实现delegate,指定缩放的视图是谁。

   
- (void)scrollViewDidScroll:(UIScrollView
*)scrollView

滚动就会触发

- (void)scrollViewWillBeginDragging:
(UIScrollView *)scrollView

开始拖拽时触发

- (void)scrollViewDidEndDragging:(UIScrollView
*)scrollView willDecelerate:(BOOL)decelerate

结束拖拽时触发

- (void)scrollViewWillBeginDecelerating:
(UIScrollView *)scrollView

开始减速时触发

- (void)scrollViewDidEndDecelerating:
(UIScrollView *)scrollView
结束减速时触发
(停⽌止时)
 
   
- (void)scrollViewDidEndZooming:(UIScrollView
*)scrollView withView:(UIView *)view atScale:
(float)scale

完成放⼤大缩⼩小触 发

- (UIView *)viewForZoomingInScrollView:
(UIScrollView *)scrollView

指定某个

UIScrollVie w的⼦子视图可以 被放⼤大缩⼩小

UIPageControl 

UIPageControl与UILabel相似 ⽤用于指⽰示当前第⼏⻚ 通常与UIScrollView配合使⽤用

currentPage //当前页

numberOfPages //指定⻚页⾯面的个数

UIPageControl从类名中可以看出,其⽗父类是UIControl 。所以可以像button⼀一样添加事件,只不过事件触发使⽤用的不是 UIControlEventsTouchUpInside⽽而是 UIControlEventsValueChanged。

通常在Scrollview滚动的时候修改pageControl的currentPage

使⽤用场景:引导⻚页,⾸首⻚页的轮播图等

contentSize决定了scrollView能否滚动,contentOffset控制内容区域的偏移量,pageEnabled控制能否整⻚页滚动。 scrollView实现缩放需要指定最⼤大缩放系数,最⼩小缩放系数,并指定

缩放的视图。 pageControl不单独使⽤用,通常与scrollView结合使⽤用。

//
// RootViewController.m
#define RandomColor [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0]
#import "RootViewController.h" @interface RootViewController ()<UIScrollViewDelegate>//当前类服从 UIScrollViewDelegate @end @implementation RootViewController - (void)viewDidLoad {
[super viewDidLoad];
//1.创建对象 //2配置属性
UIScrollView * scorll = [[UIScrollView alloc]initWithFrame:CGRectMake(, , , )];//初始化大小
scorll.backgroundColor = RandomColor;
//2.1 容量大小
scorll.contentSize = CGSizeMake(*, *);
//2.2内容区域偏移量(默认的 是 (0,0)不偏移的)
scorll.contentOffset = CGPointMake(, );//x 偏移300 y 不偏移
//2.3滚动条的显示样式
scorll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
//2.4是否显示滚动条
scorll.showsHorizontalScrollIndicator = NO;//横向滚动条(隐藏,滚动条还在仅仅是隐藏了)
scorll.showsVerticalScrollIndicator = YES;//纵向的滚动条
//2.5是否可以滚动
// scorll.scrollEnabled = NO;//默认是可以支持滚动的(我们一般使用默认值) 这里改为 NO 他就相当于一个 UIView 视图
//2.6方向锁(设置控件是否支持单方向的滑动)
scorll.directionalLockEnabled = YES;//在滑动的时候 在给定的范围去拖拽 在另外一个方向是无用的 ,如果是斜着拖动的时候,该属性就不会锁
//2.7设置 反弹效果
// scorll.bounces = NO;//默认是有反弹效果
scorll.bounces = YES;
//2.8当显示的内容区域小于scorll 的边界的时候,依然有回弹效果 (默认是有的 YES)
scorll.alwaysBounceHorizontal = NO;//水平
scorll.alwaysBounceVertical = NO;//竖直方向
//2.9点击状态条的时候 是否偏移到最顶端 (显示手机的状态的区域 显示运营商 wifi 的区域 就是状态条) 默认是支持的
scorll.scrollsToTop = YES;
//2.10设置代理 检测 scrollView 的滚动过程
scorll.delegate = self;//最早学的是 textfield 的协议
//2.11滚动条视图在拖拽的时候 缩放的比例大小
scorll.minimumZoomScale = 0.1;//最小的缩放比例 (默认是1.0 就是不缩小)
scorll.maximumZoomScale = 2.5;//最大的缩放比例
//3.添加到根视图
[self.view addSubview:scorll]; //4.释放所有权
[scorll release]; // UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 600/2- 100, 400- 100)];
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(, ,, *)];
[imageView initWithImage:[UIImage imageNamed:@"a1.jpg"]];
imageView.tag = ;
[scorll addSubview:imageView];
[imageView release]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; } #pragma MARK ----------UISCorllViewDelegate-------------------------------------------
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//scorllViewDidScroll 滚动条 ScrollView 发生滚动的时候触发
NSLog(@"scorllViewDidScroll 滚动条 ScrollView 发生滚动的时候触发 获取位置%@ 获取偏移量 ",NSStringFromCGPoint(scrollView.frame.origin));
}// any offset changes
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2){ }// any zoom scale changes // called on start of dragging (may require some time and or distance to move)
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ }
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0){ }
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ } - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ }// called on finger up as we are moving
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ }// called when scroll view grinds to a halt - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ }// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating //设置 scrollView 的缩放视图 功能
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
//viewForZoomingInScrollview: 这个方法是在拖动的过程中可以被缩放
UIImageView * View = (UIImageView *)[scrollView viewWithTag:];
return View;
}// return a view that will be scaled. if delegate returns nil, nothing happens
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2){ }// called before the scroll view begins zooming its content
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{ }// scale between minimum and maximum. called after any 'bounce' animations - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
return YES;
}// return a yes if you want to scroll to the top. if not defined, assumes YES
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{ }// called when scrolling animation finished. may be called immediately if already at top @end

UIScrollView 的一些方法

#define RandomColor [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0]

//1.创建对象

//2配置属性

UIScrollView * scorll = [[UIScrollView alloc]initWithFrame:CGRectMake(30, 50, 300, 400)];//初始化大小

scorll.backgroundColor = RandomColor;//这里的设置背景颜色

//2.1 容量大小

scorll.contentSize  = CGSizeMake(width,height);

//2.2内容区域偏移量(默认的 是 (0,0)不偏移的)

scroll.contentOffset = CGPoint(x,y);

//2.3滚动条的显示样式

sroll.indicatorSStyle = 某一样式

//2.4是否显示滚动条

scroll.showsHoriziontalScrollIndicator = NO YES 横向的

scroll.showsVerticalScrollIndicator = NO YES 竖直方向

//2.5是否可以滚动

scroll.scrollEnabled = YES NO (默认 YES)如果NO 就相当于一个 UIView了

//2.6方向锁(设置控件是否支持单方向的滑动)

scroll.directionalLockEnabled =  YES NO   在滑动的时候 在给定的范围去拖拽 在另外一个方向是无用的 ,如果是斜着拖动的时候,该属性就不会锁

//2.7设置 反弹效果

scroll.bouunces = YES NO 默认是 YES

//2.8当显示的内容区域小于scorll 的边界的时候,依然有回弹效果 (默认是有的 YES)

scroll.alwaysBounceHorizontal = YES    NO

scroll.alwaysBounceVertiocal = YES  NO

//2.9点击状态条的时候 是否偏移到最顶端 (显示手机的状态的区域 显示运营商 wifi 的区域 就是状态条) 默认是支持的

scroll.scrollToTop = YES NO

//2.10设置代理 检测 scrollView 的滚动过程

scroll.delegate = self;

//2.11滚动条视图在拖拽的时候 缩放的比例大小

scroll.minimumZoomScale =  CGFloat    //最小的缩放比例 (默认是1.0 就是不缩小)

scroll.maximumZoomScale = CGFloat   //最大的缩放比例

创建相框对象 并放到 UIScrollView 里面

UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,600, 400*2)];

[imageView initWithImage:[UIImage imageNamed:@"a1.jpg"]];

imageView.tag  = 102;

[scorll addSubview:imageView];

UIPageControl 分页控件

//创建对象

UIPageControl * page = [[UIPageControl alloc]initWithFrame:CGRectMake(x, y, width, height)];

page.backgroundColor = RandomColor;

//属性    //(设置总页数)

page.numberOfPages = number    //图片对应的点 (设置总页数)

//设置当前页数

page.currentPage = number  //设置为启动的时候为 当前第三页面 对应的点

//设置UIPageControl当前点的颜色

page.currentPageIndicatorTintColor = 设置颜色  //在点 page 的左部分 右边部分 点就会变化

//添加点击事件 (与 scrollView 结合 实现功能)

page addTarget:self  action:@selctor(设置的分页触发事件) forControlEvents:UIControlEventValueChanged(什么状态下触发该方法)

//用处:上面可以制作一个 用户引导页面

UISCorllViewDelegate 代理的协议里面实现的一组方法的实现,我们可以点开代理,然后拷出来自己实现

// 滚动条 ScrollView 发生滚动的时候触发 scorllViewDidScroll

// 缩放的图像发生缩放的时候触发  scrollViewDidZoom

// scrollView 将要进项拖拽的时候触发

//scrollView 将要结束拖拽的时候触发

//scrollView 已经结束拖拽的时候触发

// scrollView 触发时机:scrollView 将要减速 就是手指离开滚动条后触发

//scrollView 已经结束减速时候触发

// scrollView 已经结束滚动时候触发

//viewForZoomingInScrollview: 这个方法是在拖动的过程中可以被缩放

//scrollViewWillBeginZooming 是 scrollView 将要开始缩放的时候触发

//scrollViewDidEndZooming 是 scrollView 已经结束缩放时候触发

//scrollViewShouldScrollToTop 方法   对应上面点击状态条的时候 对应(设置)方法  scorll.scrollsToTop = YES; 在这个方法触发的时候会触发该方法,该方法是否支持 点击状态条 偏移到最上端 该属性默认是 YES

//scrollViewDidScrollToTop方法 是 scrollVIew 已经偏移到最上端 时候触发 效果 是刷新一下当页面前的数据 (前提是 已经设置过 scrollToTop 属性为 YES 的时候)

对应的协议实现方法代码:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//scorllViewDidScroll 滚动条 ScrollView 发生滚动的时候触发
NSLog(@"scorllViewDidScroll 滚动条 ScrollView 发生滚动的时候触发 获取位置%@ 获取偏移量 %@ ",NSStringFromCGPoint(scrollView.frame.origin),NSStringFromCGPoint(scrollView.contentOffset));
}// any offset changes // scrollView 缩放的图像发生缩放的时候触发
- (void)scrollViewDidZoom:(UIScrollView *)scrollView NS_AVAILABLE_IOS(3_2){
//scrollViewDidZoom 缩放的图像发生缩放的时候触发
NSLog(@"%s %d",__FUNCTION__,__LINE__);//注意是双下划线
}// any zoom scale changes // called on start of dragging (may require some time and or distance to move)
// scrollView 将要进项拖拽的时候触发
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
NSLog(@"scrollView 将要进项拖拽的时候触发 手指刚放上去,将要拖拽");
}
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
//scrollView 将要结束拖拽的时候触发
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0){
NSLog(@"scrollView 将要结束拖拽的时候触发");
//
}
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
// scrollView 已经结束拖拽的时候触发
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
NSLog(@"scrollView 已经结束拖拽的时候触发");
//
}
// scrollView 触发时机:scrollView 将要减速 就是手指离开滚动条后
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
NSLog(@" scrollView 触发时机:scrollView 将要减速 就是手指离开滚动条后"); }// called on finger up as we are moving //scrollView 已经结束减速
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//当停止滑动的时候 让偏移量为(0,0)
// scrollView.contentOffset = CGPointMake(0, 0);//不带动画效果
NSLog(@"scrollView 已经结束减速");
[scrollView setContentOffset:CGPointMake(, ) animated:YES];//带动画效果
//scrollViewDidEndDecelerating:
}// called when scroll view grinds to a halt // scrollView 已经结束滚动
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ // }// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating //设置 scrollView 的缩放视图 功能
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
//viewForZoomingInScrollview: 这个方法是在拖动的过程中可以被缩放
UIImageView * View = (UIImageView *)[scrollView viewWithTag:];
return View;
}// return a view that will be scaled. if delegate returns nil, nothing happens // scrollView 将要开始缩放的时候
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2){ }// called before the scroll view begins zooming its content //scrollView 已经结束缩放
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
[scrollView setZoomScale:1.0]; //缩放后还原为1.0 原来的大小
NSLog(@"scrollView 已经结束缩放");
}// scale between minimum and maximum. called after any 'bounce' animations //对应上面点击状态条的时候 对应(设置)方法 scorll.scrollsToTop = YES; 在这个方法触发的时候会触发该方法
//该方法是否支持 点击状态条 偏移到最上端 该属性默认是 YES
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{
return YES;
}// return a yes if you want to scroll to the top. if not defined, assumes YES // scrollVIew 已经偏移到最上端 时候触发 效果 是刷新一下当页面前的数据 (前提是 已经设置过 scrollToTop 属性为 YES 的时候)
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
NSLog(@"scrollVIew 已经偏移到最上端 时候触发 效果 是刷新一下当页面前的数据 (前提是 已经设置过 scrollToTop 属性为 YES 的时候)");
}// called when scrolling animation finished. may be called immediately if already at top

UISCorllViewDelegate的协议方法实例 从上面的代码块里单独摘抄

UIScrollViewDelegate 的一组协议方法

-(void)handlePage:(UIPageControl *)sender{//这是点击 ScrollView 后偏移一个页面的宽度后  UIPageControl 上面的点与页面一一对应

NSLog(@"UIPageControl 点击事件 当前pagecontrol 的页数的下标 %ld ",sender.currentPage);

//获取到 scroll

UIScrollView * scroll = (UIScrollView *)[self.view viewWithTag:111];

[scroll setContentOffset:CGPointMake(300*sender.currentPage, 0)];

//    scroll setContentOffset:<#(CGPoint)#> //是设置偏移量的方法

}

代码:

#import "AppDelegate.h"
#import "RootViewController.h"
#import "FirstLaunViewController.h"
#import "MacroHeader.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//判断是否是第一次安装启动
//NSUserDefaults 类 是用来存储用户的偏好设置 (数据 持久化 轻量级)单例模式 单例(就是程序里面只有一个)
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];//这个变量的生命周期就是软件的生命周期 存一些用户名,密码 是否第一次加载 BOOL isFirstLaunch = [user boolForKey:FIRST];//如果没有在查找出来,置为 NO "这里并不存入Key 数据"
if (!isFirstLaunch) {
//一旦发现为 NO 说明程序是第一次启动,之前没有存储过,指定 lanch 为window 的根视图控制器
//程序第一次安装需要加载用户引导界面
FirstLaunViewController * RootVC =[[FirstLaunViewController alloc]init];
self.window.rootViewController = RootVC;
[RootVC release];
}else{
//如果不是第一次安装运行,就指定主界面试图控制器为 window 的根视图
RootViewController * RootVC = [[RootViewController alloc]init];
self.window.rootViewController = RootVC;
[RootVC release];
} self.window.backgroundColor = [UIColor orangeColor]; return YES;
}

AppDelegate.m

//
// FirstLaunViewController.m #import "FirstLaunViewController.h"
#import "RootViewController.h"//本程序的 根视图控制器
#import "MacroHeader.h" @interface FirstLaunViewController ()<UIScrollViewDelegate> @end @implementation FirstLaunViewController - (void)viewDidLoad {
[super viewDidLoad];
// 第一次加载的用户引导页面
//布剧子视图
[self layoutSubViews];
} -(void)layoutSubViews{
[self setUpScrollView];//布局 scroll
[self setUpPageControl]; }
-(void)setUpScrollView{
UIScrollView * scroll = [[UIScrollView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];//[UIScreen mainScreen].bounds 就不要再加 [] le
scroll.tag = ;
// scroll.contentOffset = CGPointMake(self.view.frame.size.width,0);
//正页滑动
scroll.pagingEnabled = YES;
scroll.delegate = self;//设置代理
scroll.contentSize = CGSizeMake(kScreenWidth * kImageCount, kScreenHeight);
scroll.showsHorizontalScrollIndicator = NO;//不让横向的滚动条显示
//放图片
for (int i = ; i < kImageCount; i++) {
// UIImageView * imageView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
UIImageView * imageView = [[UIImageView alloc]initWithFrame: CGRectMake(kScreenWidth * i, , kScreenWidth, kScreenHeight)];
NSString * imageName = [NSString stringWithFormat:kPictureName,i+];
NSString * imagePath = [[NSBundle mainBundle]pathForResource:imageName ofType:kPictureType];
UIImage * image = (UIImage *)[UIImage imageWithContentsOfFile:imagePath];
// [imageView addSubview:image];
[imageView setImage:image];
imageView.tag = + i;
// imageView.frame = CGRectMake(kScreenWidth * i, 0, kScreenWidth, kScreenHeight);
// [self.view addSubview:imageView];
[scroll addSubview:imageView];//注意是添加到 scroll
[imageView release];
//最后一张需要轻怕手势(浏览最后一张图片轻拍后进入页面)
if(i == kImageCount - ){
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
[imageView addGestureRecognizer:tap];//这里不能少了这一步,给 imageView 指定轻拍对象
//打开用户交互
imageView.userInteractionEnabled = YES;
[tap release];
}
} [self.view addSubview:scroll];
[scroll release];
}
-(void)setUpPageControl{
UIPageControl * page = [[UIPageControl alloc]initWithFrame:CGRectMake((kScreenWidth- )/, kScreenHeight - , , )];//先确定控件的 宽 高 xy 就相应的确定了
page.tag = ;
//设置其余页的颜色
page.pageIndicatorTintColor = [UIColor orangeColor];
// page.currentPage = kImageCount;//页面总页数不是这样写的 page.currentPage 是什么?
page.numberOfPages = kImageCount;
//当前页面的颜色
page.currentPageIndicatorTintColor = [UIColor lightGrayColor];
// page.currentPageIndicatorTintColor = [UIColor redColor];
// UIScrollView * scroll = (UIScrollView *)[self.view viewWithTag:101];
// [scroll addSubview:page];
// page.backgroundColor = [UIColor redColor];//测试一下位置
[self.view addSubview:page];
[page release]; //添加响应的触发方法 (使用协议 这里就不需要了)
// [page addTarget:self action:@selector(handlePage:) forControlEvents:UIControlEventValueChanged];
}
#pragma mark -------Page页面的点与页面下标一致---------
//UIPageControl
//-(void)handlePage:(UIPageControl *)page{
// UIPageControl * pageview = [[UIPageControl alloc]init];
// pageview = (UIPageControl *)[self.view viewWithTag:102];
//
// UIScrollView * scrollview = [[UIScrollView alloc]init];
// scrollview = (UIScrollView *)[self.view viewWithTag:101];
//
//} #pragma mark -------轻拍进入程序主页面---------
//轻怕手势
-(void)handleTap:(UITapGestureRecognizer *)tap{
//当点击最后一张的时候,就意味着用户引导页已经结束,要进入到程序的主界面,这时候要将对应的 key 保存到轻量级的 NSUserDefaults
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];//整个程序运行期间程序不会被回收
// [user boolForKey:@"first"]==YES;
[user setBool:YES forKey:FIRST];//当点击最后一张的时候,就意味着用户引导页已经结束,要进入到程序的主界面
//立即更新立即保存 同步,立即修改 存入到本地内存的字符串的值 这个方法是系统每隔一段时间去调用的方法(系统自己去保存)
[user synchronize];
//进入程序主界面(就是重新指定根视图控制器)
RootViewController * mainVC = [[RootViewController alloc]init];
//更改 wiindow 的根视图控制器 为主界面的视图控制器 mainVC
[UIApplication sharedApplication].keyWindow.rootViewController = mainVC;//UIApplication 也是一个单例对象
[mainVC release];
} #pragma mark -------UIScrollViewDelegate 协议实现---------
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;{
UIPageControl * page = (UIPageControl *)[self.view viewWithTag:];
page.currentPage = scrollView.contentOffset.x/kScreenWidth;
// NSLog(@"%f %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

FirstLaunViewController.m用户引导页面

#ifndef UseDemo_MacroHeader_h
#define UseDemo_MacroHeader_h //该文件可以定义工程里所有用到的宏 在需要的时候直接 导入该文件即可 //定义在 FirstLaunViewController.m里定义的 宏
#define kScreenWidth [[UIScreen mainScreen]bounds].size.width
#define kScreenHeight [[UIScreen mainScreen]bounds].size.height
#define kImageCount 6 //好处是方便每次修改图片的张数
#define kPictureName @"v6_guide_%d"
#define kPictureType @"png"
#define FIRST @"firstLaunch" #endif

MacroHeader.m 宏定义页面

上一篇:如何为元组中的每个元素命名,提高程序可读性---Python数据结构与算法相关问题与解决技巧


下一篇:Google最新截屏案例详解