iOS新版本特性(引导页)

图片规则 和命名要求
4S 640 X 960 [email protected] 如:[email protected]
5S 640 X 1136 [email protected] 如:[email protected]
6 750 X 1334 [email protected] 如:[email protected]
6Plus 1242 X 2208 [email protected] 如:[email protected]

在XX.m文件 视图什么的可以分开写

#import "YJNewfeatureViewController.h"
#import "LCLoginViewController.h"
#define kNewfeatureCount 4

@interface YJNewfeatureViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong)UIPageControl *pageControl;

@end

@implementation YJNewfeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadScrollView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 创建scrollView
- (void)loadScrollView
{
    // 1、创建一个scrollView:显示所有的新特性
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds;
    scrollView.delegate = self;
    [self.view addSubview:scrollView];

    // 2、添加图片到scrollView中
    CGFloat scrollW = scrollView.width;
    CGFloat scrollH = scrollView.height;
    for (int i = 0; i < kNewfeatureCount; i++)
    {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.width = scrollW;
        imageView.height = scrollH;
        imageView.y = 0;
        imageView.x = i * scrollW;
        NSString *name = [NSString stringWithFormat:@"new_feature_%d", i];
        imageView.image = [UIImage imageNamed:name];
        [scrollView addSubview:imageView];

// 如果是最后一个imageView 就往里面添加其他内容
        if (i == kNewfeatureCount - 1)
        {
            [self setupLastImageView:imageView];
        }
    }

    // 3、设置scrollView的其他属性
    // 如果想要某个方向上不能滚动,那么这个方向对应的尺寸数值传0即可
    scrollView.contentSize = CGSizeMake(kNewfeatureCount * scrollW, 0);
    scrollView.bounces = NO;
    scrollView.pagingEnabled = YES;
    scrollView.showsHorizontalScrollIndicator = NO;

    // 4、添加pageControl 展示目前看到的是第几页
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.numberOfPages = kNewfeatureCount;
    pageControl.centerX = scrollW * 0.5;
    pageControl.centerY = scrollH - 20;
    pageControl.userInteractionEnabled = NO;
    pageControl.pageIndicatorTintColor = [UIColor RGBColor:189 green:189 blue:189 alpha:1];
    pageControl.currentPageIndicatorTintColor = [UIColor RGBColor:253 green:98 blue:42 alpha:1];
    self.pageControl = pageControl;

    [self.view addSubview:pageControl];

}

#pragma mark - 活动的时候改变page
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    double page = scrollView.contentOffset.x / scrollView.width;
    // 四舍五入计算出页码
    self.pageControl.currentPage = (int)(page + 0.5);
}

#pragma mark - 在最后一个图片上方一个按钮
- (void)setupLastImageView:(UIImageView *)imageView
{
    // 1开启交互功能
    imageView.userInteractionEnabled = YES;
    // 2.点击进入
    UIButton *startBtn = [[UIButton alloc] init];
    startBtn.frame = CGRectMake(kScreenWidth / 2 - 75, kScreenHeight / 1.2, 170, 50);
    startBtn.showsTouchWhenHighlighted = YES;
    startBtn.backgroundColor = [UIColor redColor];
    [startBtn addTarget:self action:@selector(startClick) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:startBtn];
}

#pragma mark - 开启按钮触发事件
- (void)startClick
{
    // 1、创建window对象
    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    // 2、创建登录对象
    UIStoryboard *stoyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    LCLoginViewController *loginVC = [stoyboard instantiateViewControllerWithIdentifier:@"LCLoginViewController"];
    UINavigationController *navLoginVC = [[UINavigationController alloc] initWithRootViewController:loginVC];

    // 3.设置跟控制器
    window.rootViewController = navLoginVC;

}
@end

在appDelegate.m文件判断版本号 如果发现新版本·显示引导页

#pragma mark - 判断新版本和设置主控制器
- (void)newVersionAndRootViewController
{

    // 2.设置跟控制器
    // 版本新特性
    NSString *key = @"CFBundleVersion";

    // 上一次的使用版本 (存储在沙盒中的版本号)
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults]objectForKey:key];

    // 当前软件的版本号(从Info.plist)
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];

    // 判断版本号是否相同
    if ([currentVersion isEqualToString:lastVersion])
    {
        // 如果相同跳到主控制 代码这里写
    }
    else
    {
        // 如果发现新版本 就先把引导页设置为跟控制
        UIStoryboard *stoyboard = [UIStoryboard storyboardWithName:@"YJNewfeatureStoryboard" bundle:nil];
        YJNewfeatureViewController *newfeatureVC = [stoyboard instantiateViewControllerWithIdentifier:@"YJNewfeatureViewController"];
        // 新版本
        self.window.rootViewController = newfeatureVC;
        //将当前的版本号存进沙盒
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

你可能感兴趣的:(iOS引导页,iOS新版本特性)