添加app第一次啟動頁面

來源:互聯網
上載者:User

標籤:

一、添加幾個成員變數

@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(0, 0, MainScreen_width, MainScreen_height)];                scrollView.contentSize = CGSizeMake((_imageArray.count + 1)*MainScreen_width, MainScreen_height);        //設定反野效果,不允許反彈,不顯示水平滑動條,設定代理為自己        scrollView.pagingEnabled = YES;//設定分頁        scrollView.bounces = NO;        scrollView.showsHorizontalScrollIndicator = NO;        scrollView.delegate = self;        [self addSubview:scrollView];        _bigScrollView = scrollView;                for (int i = 0; i < _imageArray.count; i++) {            UIImageView *imageView = [[UIImageView alloc]init];            imageView.frame = CGRectMake(i * MainScreen_width, 0, MainScreen_width, MainScreen_height);            UIImage *image = [UIImage imageNamed:_imageArray[i]];            imageView.image = image;                        [scrollView addSubview:imageView];        }                UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(MainScreen_width/2, MainScreen_height - 60, 0, 40)];        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 = 1;        [scrollView addGestureRecognizer:singleRecognizer];            }        return self;}

三、添加一個手勢,在周到最後一頁的時候,讓整個view隱藏

-(void)handleSingleTapFrom{    if (_pageControl.currentPage == 3) {                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;            }    }

 

添加app第一次啟動頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.