自定義App首次啟動(dòng)引導(dǎo)頁

define BOOLFORKEY @"GuidePage"

@interface GuidePageView ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIPageControl *pageControl;

@end

@implementation GuidePageView

  • (instancetype)initWithFrame:(CGRect)frame
    {
    if (self = [super initWithFrame:frame]) {

      [self show];
    

    }

    return self;
    }

  • (void)show
    {

    if (![[NSUserDefaults standardUserDefaults] boolForKey:BOOLFORKEY]) {

      [[NSUserDefaults standardUserDefaults] setBool:YES forKey:BOOLFORKEY];
      // 自定義引導(dǎo)界面
      [self pushGuideView];
    

    }

}

// 加載視圖

  • (void)pushGuideView
    {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.frame = window.bounds;
    [window addSubview:self];

    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self addSubview:_scrollView];
    _scrollView.backgroundColor = [UIColor whiteColor];
    _scrollView.delegate = self;
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 4, SCREEN_HEIGHT);
    _scrollView.bounces = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.showsHorizontalScrollIndicator = NO;

    for (NSInteger i = 0; i < 4; i++) {

      UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
      NSString *imageName = [NSString stringWithFormat:@"start_%ld",i + 1];
      imageView.image = [UIImage imageNamed:imageName];
      imageView.userInteractionEnabled = YES;
      
      if (i == 3) {
          
          UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeSystem];
          [startBtn setTitle:@"開始體驗(yàn)" forState:UIControlStateNormal];
          startBtn.layer.masksToBounds = YES;
          [startBtn setTitleColor:[UIColor colorWithHex:@"722b04"] forState:UIControlStateNormal];
          startBtn.titleLabel.font = [UIFont systemFontOfSize:19];
          startBtn.layer.cornerRadius = 20;
          startBtn.backgroundColor = [UIColor colorWithHex:kAppDefaultColor_yellow];
          [startBtn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
          [imageView addSubview:startBtn];
    
          [startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
              make.bottom.equalTo(imageView.mas_bottom).offset(-50);
              make.centerX.equalTo(imageView.mas_centerX);
              make.width.equalTo(@170);
              make.height.equalTo(@40);
          }];
          
      }
      
      [_scrollView addSubview:imageView];
    

    }

    _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.0, SCREEN_HEIGHT * 0.9, SCREEN_WIDTH * 1.0, SCREEN_HEIGHT * 0.1)];
    _pageControl.currentPage = 0;
    _pageControl.numberOfPages = 4;
    _pageControl.pageIndicatorTintColor = [UIColor grayColor];
    _pageControl.currentPageIndicatorTintColor = [UIColor colorWithHex:kAppDefaultColor_yellow];
    [self addSubview:_pageControl];
    }

  • (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollview
    {
    int page = scrollview.contentOffset.x / scrollview.frame.size.width;
    [_pageControl setCurrentPage:page];
    }

  • (void)buttonClick
    {
    [UIView animateWithDuration:1.5 animations:^{

      self.alpha = 0;
    

    } completion:^(BOOL finished) {

      [self removeFromSuperview];
    

    }];
    }

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容