新特性引导页

作者: laitys | 来源:发表于2016-06-08 11:55 被阅读175次
    Paste_Image.png

    在我们做程序维护和版本迭代工作中,我们经常会做新特性界面(闪屏页过后的引导界面),做新特性界面的逻辑思维就是在App被初次下载或版本升级之后才出现,一般到新特性界面的最后一页用户点击立即体验后,跳转到之前的业务逻辑界面,即未注册登录过的用户跳转到注册登录界面,登录过的用户,跳转到用户之前登录过停留的界面.

    案例:

    • 判断应用的版本号是否更新
     ///  判断是否是新版本
     - (BOOL)isNewVersion{
    
     //获取Bundle文件夹下应用当前版本号
    NSDictionary *infoDictionary = [NSBundle mainBundle].infoDictionary;
    NSString *currentVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
     
     //偏好设置中获取上一次版本号
    NSString *sandboxKey = @"sandboxKey";
    NSString *sandboxVersion = [[NSUserDefaults standardUserDefaults]stringForKey:sandboxKey];
    BOOL isNew = ![currentVersion isEqualToString:sandboxVersion];
    
     //如果是新版本号 保存到偏好设置
    if (isNew) {
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:sandboxKey];
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
    
    return isNew;
    }
    
    • 在AppDelegate的didFinishLaunching里调用判断版本号是否更新方法 如果是跳到新特性控制器如果不是还走原来的业务逻辑.
      //判断是否是新版本 如果是则跳到新特性界面(视频导航页)
      if ([self isNewVersion]) {
      self.window.rootViewController = [[RTNewFeatureViewController alloc]init];
      }
      //如果不是新版本,根据自己的业务需求 提供一个方法确定window的根控制器
      [self switchWindowRootViewController];
    • 自定义新特性控制器
      @interface RTNewFeatureViewController () <RTNewFeatureCellDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
      //流水布局
      @property (nonatomic, strong) UICollectionViewFlowLayout *layout;
      @property (nonatomic, strong) UICollectionView *collectionView;
      @property (nonatomic, strong) UIPageControl *pageControl;
      @end

       @implementation RTNewFeatureViewController
      
       static NSString * const reuseIdentifier = @"RTNewFeatureCell";
      
       - (void)viewDidLoad {
             [super viewDidLoad];
             [self prepareForUI];
             [[UIApplication sharedApplication]setStatusBarHidden:YES];
          }
      
        - (void)prepareForUI{
            [self.view addSubview:self.collectionView];
            [self.view addSubview:self.pageControl];
      
            [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
               make.bottom.equalTo(self.view).offset(-15);
               make.centerX.equalTo(self.view);
            }];
      
            self.collectionView.delegate = self;
            self.collectionView.dataSource = self;
            self.collectionView.pagingEnabled = YES;
            self.collectionView.bounces = NO;
            self.collectionView.showsHorizontalScrollIndicator = NO;
            self.layout.itemSize = [UIScreen mainScreen].bounds.size;
            self.layout.minimumInteritemSpacing = 0;
            self.layout.minimumLineSpacing = 0;
            self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
      
           [self.collectionView registerClass:[RTNewFeatureCell class]  forCellWithReuseIdentifier:reuseIdentifier];
      
         }
      
           #pragma mark - UICollectionViewDataSource && DataSource
      
          - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
      
            return 2;
        }
      
       - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView      cellForItemAtIndexPath:(NSIndexPath *)indexPath {
              RTNewFeatureCell  *cell = [collectionView  dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
              cell.index = (int)indexPath.row;
              cell.delegate = self;
              return cell;
      }
      
           #pragma mark - RTNewFeatureCellDelegate
      
            ///  按钮点击事件
       -(void)cellButtonDidClick:(RTNewFeatureCell *)cell
          {
             AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
             NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
             if (indexPath.row) {
                    //跳转到开始体验页
                   appDelegate.window.rootViewController = nil;
                   [[UIApplication sharedApplication]setStatusBarHidden:NO];
                   [appDelegate switchWindowRootViewController];
      
            }else{
                      //跳转到百度
                NSURL *url = [NSURL URLWithString:@"http://www.baidu.com"];
               [[UIApplication sharedApplication]openURL:url];
           }
      
         }
      
          ///  set pageControl
      - (void)scrollViewDidScroll:(UIScrollView *)scrollView
       {
             if(scrollView.contentOffset.x > [UIScreen mainScreen].bounds.size.width/2)
          {
               self.pageControl.currentPage = 1;
         }else{
               self.pageControl.currentPage = 0;
         }   
      }
      
         #pragma mark - lazyLoad
      
      - (UIPageControl *)pageControl
      {
           if (_pageControl == nil) {
               _pageControl = [[UIPageControl alloc]init];
               _pageControl.numberOfPages = 2;
               _pageControl.pageIndicatorTintColor = kRTColorWithHEX(0xC9C9C9, 1);
               _pageControl.currentPageIndicatorTintColor = kRTColorWithHEX(0xF88558, 1);
        }
              return _pageControl;
      }
      
      - (UICollectionView *)collectionView
       {
            if (_collectionView == nil) {
      
                   _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0,  self.view.bounds.size.width, self.view.bounds.size.height)  collectionViewLayout:self.layout];
      _collectionView.backgroundColor = [UIColor brownColor];
      
       }
            return _collectionView;
      }
      
        -(UICollectionViewFlowLayout *)layout
        {
               if (_layout == nil) {
                    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
                    self.layout = layout;
               }
             return _layout;
        }
      

    改变一下版本号测试一下

    456.gif

    相关文章

      网友评论

        本文标题:      新特性引导页

        本文链接:https://www.haomeiwen.com/subject/qoaddttx.html