
正文
添加app第一次启动页面
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、添加几个成员变量
@interface hDisplayView ()<UIScrollViewDelegate>
{
UIScrollView *_bigScrollView;
NSMutableArray *_imageArray;
UIPageControl *_pageControl;
}
二、添加构造方法
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_imageArray = [@[@"闪屏1.png",@"闪屏2.png", @"闪屏3.png",@"闪屏4.png"]mutableCopy]; // _imageArray = [NSMutableArray arrayWithObjects:@"闪屏1.png",@"闪屏2.png", @"闪屏3.png",@"闪屏4.png", nil]; UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(, , MainScreen_width, MainScreen_height)]; scrollView.contentSize = CGSizeMake((_imageArray.count + )*MainScreen_width, MainScreen_height);
//设置反野效果,不允许反弹,不显示水平滑动条,设置代理为自己
scrollView.pagingEnabled = YES;//设置分页
scrollView.bounces = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
[self addSubview:scrollView];
_bigScrollView = scrollView; for (int i = ; i < _imageArray.count; i++) {
UIImageView *imageView = [[UIImageView alloc]init];
imageView.frame = CGRectMake(i * MainScreen_width, , MainScreen_width, MainScreen_height);
UIImage *image = [UIImage imageNamed:_imageArray[i]];
imageView.image = image; [scrollView addSubview:imageView];
} UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(MainScreen_width/, MainScreen_height - , , )];
pageControl.numberOfPages = _imageArray.count;
pageControl.backgroundColor = [UIColor clearColor];
[self addSubview:pageControl]; _pageControl = pageControl; //添加手势
UITapGestureRecognizer *singleRecognizer;
singleRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTapFrom)];
singleRecognizer.numberOfTapsRequired = ;
[scrollView addGestureRecognizer:singleRecognizer]; } return self;
}
三、添加一个手势,在周到最后一页的时候,让整个view隐藏
-(void)handleSingleTapFrom
{
if (_pageControl.currentPage == ) { self.hidden = YES; }
}
四、添加一个scrollview的代理方法,让pagecontrol在scrollview的中间位置
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (scrollView == _bigScrollView) { CGPoint offSet = scrollView.contentOffset; _pageControl.currentPage = offSet.x/(self.bounds.size.width);//计算当前的页码
[scrollView setContentOffset:CGPointMake(self.bounds.size.width * (_pageControl.currentPage), scrollView.contentOffset.y) animated:YES]; } if (scrollView.contentOffset.x == (_imageArray.count) *MainScreen_width) { self.hidden = YES; } }








