1.AppDelegate
NSString *key = @"CFBundleVersion";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//存入本地版本
NSString *lastVersion = [defaults stringForKey:key];
//取得当前版本
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
//如果之前的版本和当前的版本相同 说明没有新版本
if ([currentVersion isEqualToString:lastVersion]) {
self.window.rootViewController = [[MainTabBarViewController alloc] init];
}else{//说明有新版本,显示新特性页面
self.window.rootViewController = [[NewFeature alloc] init];
//将新版本存入本地
[defaults setObject:currentVersion forKey:key];
[defaults synchronize];
}
2.NewFeature.m
#define NewfeatureImageCount 3
@interface NewFeature()<UIScrollViewDelegate>
@property (nonatomic, weak) UIPageControl *pageControl;
@end
@implementation NewFeature
- (void)viewDidLoad
{
[super viewDidLoad];
//1.设置scrollView
[self scrollView];
// 2.添加pageControl
[self setupPageControl];
}
- (void)scrollView
{
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:scrollView];
scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 3, 0);
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.bounces = NO;
scrollView.delegate = self;
// 添加图片
for (int index = 0; index < NewfeatureImageCount; index++) {
NSString *name = [NSString stringWithFormat:@"new_feature_%d", index+1];
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:name]];
image.frame = CGRectMake(index * scrollView.frame.size.width, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[scrollView addSubview:image];
image.userInteractionEnabled = YES;
if (index == NewfeatureImageCount - 1) {
[self startBtn:image];
}
}
}
/**
* 添加pageControl
*/
- (void)setupPageControl
{
// 1.添加
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.numberOfPages = NewfeatureImageCount;
CGFloat centerX = self.view.frame.size.width * 0.5;
CGFloat centerY = self.view.frame.size.height - 30;
pageControl.center = CGPointMake(centerX, centerY);
pageControl.bounds = CGRectMake(0, 0, 100, 30);
pageControl.userInteractionEnabled = NO;
[self.view addSubview:pageControl];
self.pageControl = pageControl;
// 2.设置圆点的颜色
pageControl.currentPageIndicatorTintColor = IWColor(253, 98, 42);
pageControl.pageIndicatorTintColor = IWColor(189, 189, 189);
}
//开始微博按钮和checkBox
- (void)startBtn:(UIImageView *)image
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
[button setTitle:@"开始体验" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.frame = CGRectMake((SCREEN_WIDTH - 100) / 2, 350, 100, 30);
button.titleLabel.font = [UIFont systemFontOfSize:14];
[button addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];
[image addSubview:button];
UIButton *checkBox = [UIButton buttonWithType:UIButtonTypeCustom];
[checkBox setTitle:@"分享给大家" forState:UIControlStateNormal];
[checkBox setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[checkBox setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateNormal];
[checkBox setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateSelected];
checkBox.frame = CGRectMake((SCREEN_WIDTH - 200)/2, button.frame.origin.y - 30, 200, 30);
[checkBox addTarget:self action:@selector(checkBoxAction:) forControlEvents:UIControlEventTouchUpInside];
[image addSubview:checkBox];
}
#pragma mark - 开始微博按钮
- (void)start
{
self.view.window.rootViewController = [[MainTabBarViewController alloc] init];
}
#pragma mark - checkBox点击事件
- (void)checkBoxAction:(UIButton *)checkBox
{
checkBox.selected = !checkBox.selected;
}
#pragma mark - UIScrollViewDelegate
/**
* 只要UIScrollView滚动了,就会调用
*
*/
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// 1.取出水平方向上滚动的距离
CGFloat offsetX = scrollView.contentOffset.x;
// 2.求出页码
double pageDouble = offsetX / scrollView.frame.size.width;
int pageInt = (int)(pageDouble + 0.5);
self.pageControl.currentPage = pageInt;
}