一、首先判断版本号高低,在info.plist中,有几个版本号,
要想判断版本号的高低,需要做三件事,
一 拿到以前的版本号
NSString *key = @"CFBoundleVersion";
//上一次的使用版本(存储在沙盒中的版本号)
NSString *lastVersion = [[NSUserDefaultsstandardUserDefaults]objectForKey:key];
二 拿到当前的版本号
NSString *currentVersion = [NSBundlemainBundle].infoDictionary[key];
三 比较俩个版本号
if([currentVersionisEqualToString:lastVersion]){//版本号相同:这次打开和上次打开的是同一个版本
self.window.rootViewController = [[ViewControlleralloc] init];
}else{//这次打开的版本和上一次不一样,显示新特性
self.window.rootViewController = [[YYNewViewControlleralloc] init];
// 如当前版本号大于以前的的版本号,将当前的版本号存进沙盒
[[NSUserDefaultsstandardUserDefaults]setObject:currentVersionforKey:key];
[[NSUserDefaultsstandardUserDefaults] synchronize];
}
#define YYNewfeatureCount 4
// RGB颜色
#define YYColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
- (void)viewDidLoad{
[superviewDidLoad];
// 1.创建一个scrollView:显示所有的新特性图片
UIScrollView *scrollView = [[UIScrollViewalloc] init];
scrollView.frame = self.view.bounds;
[self.viewaddSubview:scrollView];
self.scrollView = scrollView;
// 2.添加图片到scrollView中
CGFloat scrollW = scrollView.width;
CGFloat scrollH = scrollView.height;
for (int i =0; i<YYNewfeatureCount; i++) {
UIImageView *imageView = [[UIImageViewalloc] init];
imageView.width = scrollW;
imageView.height = scrollH;
imageView.y = 0;
imageView.x = i * scrollW;
// 显示图片
NSString *name = [NSStringstringWithFormat:@"new_feature_%d", i +1];
imageView.image = [UIImageimageNamed:name];
[scrollView addSubview:imageView];
// 如果是最后一个imageView,就往里面添加其他内容
if (i == YYNewfeatureCount -1) {
[self setupLastImageView:imageView];
}
}
// 3.设置scrollView的其他属性
// 如果想要某个方向上不能滚动,那么这个方向对应的尺寸数值传0即可
scrollView.contentSize = CGSizeMake(YYNewfeatureCount * scrollW,0);
scrollView.bounces = NO; // 去除弹簧效果
scrollView.pagingEnabled = YES;
scrollView.showsHorizontalScrollIndicator =NO;
scrollView.delegate = self;
// 4.添加pageControl:分页,展示目前看的是第几页
UIPageControl *pageControl = [[UIPageControlalloc] init];
pageControl.numberOfPages = YYNewfeatureCount;
pageControl.backgroundColor = [UIColorredColor];
pageControl.currentPageIndicatorTintColor = YYColor(253,98,42);
pageControl.pageIndicatorTintColor = YYColor(189, 189, 189);
pageControl.centerX = scrollW * 0.5;
pageControl.centerY = scrollH - 50;
[self.viewaddSubview:pageControl];
self.pageControl = pageControl;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
double page = scrollView.contentOffset.x / scrollView.width;
// 四舍五入计算出页码
self.pageControl.currentPage = (int)(page +0.5);
}
//初始化最后一个imageView
- (void)setupLastImageView:(UIImageView *)imageView
{
// 开启交互功能
imageView.userInteractionEnabled =YES;
// 1.分享给大家(checkbox)
UIButton *shareBtn = [[UIButtonalloc] init];
[shareBtn setImage:[UIImageimageNamed:@"new_feature_share_false"]forState:UIControlStateNormal];
[shareBtn setImage:[UIImageimageNamed:@"new_feature_share_true"]forState:UIControlStateSelected];
[shareBtn setTitle:@"分享给大家"forState:UIControlStateNormal];
[shareBtn setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
shareBtn.titleLabel.font = [UIFontsystemFontOfSize:15];
shareBtn.width = 200;
shareBtn.height = 30;
shareBtn.centerX = imageView.width *0.5;
shareBtn.centerY = imageView.height *0.65;
[shareBtn addTarget:selfaction:@selector(shareClick:)forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:shareBtn];
shareBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
// 2.开始首页
UIButton *startBtn = [[UIButtonalloc] init];
[startBtn setBackgroundImage:[UIImageimageNamed:@"new_feature_finish_button"]forState:UIControlStateNormal];
[startBtn setBackgroundImage:[UIImageimageNamed:@"new_feature_finish_button_highlighted"]forState:UIControlStateHighlighted];
startBtn.size = startBtn.currentBackgroundImage.size;
startBtn.centerX = shareBtn.centerX;
startBtn.centerY = imageView.height *0.75;
[startBtn setTitle:@"开始首页"forState:UIControlStateNormal];
[startBtn addTarget:selfaction:@selector(startClick)forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:startBtn];
}
- (void)shareClick:(UIButton *)shareBtn
{
// 状态取反
shareBtn.selected = !shareBtn.isSelected;
}
- (void)startClick
{
// 切换到主界面
UIWindow *window = [UIApplicationsharedApplication].keyWindow;
window.rootViewController = [[YYTabBarViewControlleralloc] init];
}