App在第一次下载的时候都有一个滑动介绍App的几个页面 这个功能实现也比较简单 不多说上代码
@implementation lanchimageViewController<UIScrollViewDelegate>//记得遵循ScrollView代理
- (void)viewDidLoad {
[superviewDidLoad];
[selfaddScrollView];
[selfaddPageControl];
// Do any additional setup after loading the view.
}
- (void)addScrollView{
UIScrollView *scroll = [[UIScrollViewalloc]initWithFrame:[UIScreenmainScreen].bounds];
scroll.backgroundColor = [UIColorgrayColor];
//设置按页滚动
scroll.pagingEnabled =YES;
scroll.bounces =NO;
scroll.tag =102;
scroll.showsHorizontalScrollIndicator =NO;
scroll.contentSize =CGSizeMake(SIZE.width *3, SIZE.height);
//将当前视图控制器设置为scroll的代理人
scroll.delegate =self;
for (int i =0; i <3; i++) {
NSString * imageN = [NSStringstringWithFormat:@"wel%d",i +1];
UIImageView *imageV = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:imageN]];
imageV.frame =CGRectMake(SIZE.width * i,0, SIZE.width,SIZE.height);
// 13632741785
[scroll addSubview:imageV];
if (i ==2) {
//打开该图片的用户交互****************************
imageV.userInteractionEnabled =YES;
UITapGestureRecognizer *tapG = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(handletapG:)];
[imageV addGestureRecognizer:tapG];
}
}
[self.viewaddSubview:scroll];
}
- (void)addPageControl{
UIPageControl *pageC = [[UIPageControlalloc]initWithFrame:CGRectMake(40,SIZE.height -50, SIZE.width -80,50)];
//设置页数(默认状态为1)
pageC.numberOfPages =3;
pageC.tag =101;
//设置选中页码和未被选中页码颜色
pageC.currentPageIndicatorTintColor = [UIColorcolorWithRed:236/255.0green:150/255.0blue:135.0alpha:1.0];
pageC.pageIndicatorTintColor = [UIColorwhiteColor];
//为pageControll添加响应事件
[pageC addTarget:selfaction:@selector(handlePage:)forControlEvents:UIControlEventValueChanged];
//决定当只有一页的时候pageC是否显示(默认状态为NO)
pageC.hidesForSinglePage =YES;
[self.viewaddSubview:pageC];
}
#pragma mark pageControll - Action
- (void)handlePage:(UIPageControl *)pageC{
//获得scrollView
UIScrollView *scroll = (UIScrollView *)[self.viewviewWithTag:102];
//获得当前页码下标
NSInteger pageNum = pageC.currentPage;
[scroll setContentOffset:CGPointMake(pageNum *SIZE.width,0)animated:YES];
}
#pragma mark 实现协议
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//获取pageController
UIPageControl *pageC = (UIPageControl *)[self.viewviewWithTag:101];
//设置pageC下标为页面数(水平方向偏移量/单个图片宽度)
pageC.currentPage = scrollView.contentOffset.x /SIZE.width;
}
#pragma mark 处理轻拍手势
- (void)handletapG:(UITapGestureRecognizer *)tapG{
LoginViewController * viewC = [[LoginViewControlleralloc]init];
//获取应用程序主窗口 跳转到视图控制器
[UIApplicationsharedApplication].keyWindow.rootViewController = viewC;
}