1.手动创建窗口,启动。判断是否有新版本,展示新特性界面
//
// AppDelegate.m
#import "AppDelegate.h"
#import "NewFeatureViewController.h"
#define VersionKey @"version"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// 创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor redColor];
// 判断有木有最新的版本号
// 从info.plist获取软件版本号
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleInfoDictionaryVersion"];
NSString *oldVersion = [[NSUserDefaults standardUserDefaults] objectForKey:VersionKey];
UIViewController *rootVC = nil;
if ([currentVersion isEqualToString:oldVersion]) {
// 没有新版本
rootVC = [[UITabBarController alloc] init];
}else{
rootVC = [[NewFeatureViewController alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:VersionKey];
}
// 设置窗口的根控制器
self.window.rootViewController = rootVC;
// 显示窗口
[self.window makeKeyAndVisible];
return YES;
}
@end
2.新特性
//
// NewFeatureViewController.h
#import <UIKit/UIKit.h>
@interface NewFeatureViewController : UICollectionViewController
@end
//
// NewFeatureViewController.m
#import "NewFeatureViewController.h"
#import "NewFeatureCell.h"
#define ScreenBounds [UIScreen mainScreen].bounds
@interface NewFeatureViewController ()
@end
@implementation NewFeatureViewController
static NSString * const reuseIdentifier = @"Cell";
- (instancetype)init
{
// 流水布局对象
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
// 设置cell尺寸
layout.itemSize = CGSizeMake(ScreenBounds.size.width, ScreenBounds.size.height);
// cell间距
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
// 滚动的方向
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
return [super initWithCollectionViewLayout:layout];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = NO;
// 弹簧效果
self.collectionView.bounces = NO;
// 滚动条
self.collectionView.showsHorizontalScrollIndicator = NO;
// 分页
self.collectionView.pagingEnabled = YES;
// 注册cell
[self.collectionView registerClass:[NewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
}
#pragma mark <UICollectionViewDataSource>
// 有多少组
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
// 返回第section组有多少个cell
#define Pages 4
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return Pages;
}
/**
* 返回cell
*/
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide%ldBackground",indexPath.item + 1]];
// 告诉cell什么时候是最后一个
[cell setupIndexPath:indexPath count:Pages];
return cell;
}
@end
//
// NewFeatureCell.h
#import <UIKit/UIKit.h>
@interface NewFeatureCell : UICollectionViewCell
@property(nonatomic,strong)UIImage *image;
- (void)setupIndexPath:(NSIndexPath *)indexPath count:(NSInteger)pagesCount;
@end
//
// NewFeatureCell.m
#import "NewFeatureCell.h"
#define ScreenBounds [UIScreen mainScreen].bounds
@interface NewFeatureCell()
@property(nonatomic,weak)UIImageView *imageView;
@property(nonatomic,weak)UIButton *startButton;
@end
@implementation NewFeatureCell
- (UIButton *)startButton
{
if (_startButton == nil) {
UIButton *btn = [[UIButton alloc] init];
[btn setBackgroundImage:[UIImage imageNamed:@"guideStart"] forState:UIControlStateNormal];
[btn sizeToFit];
btn.center = CGPointMake(self.bounds.size.width * 0.5, self.bounds.size.height * 0.9);
[btn addTarget:self action:@selector(startButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:btn];
_startButton = btn;
}
return _startButton;
}
/**
* 点击了startButton按钮
*/
- (void)startButtonClicked
{
// 切换根控制器
self.window.rootViewController = [[UITabBarController alloc] init];
}
- (UIImageView *)imageView
{
if (_imageView == nil) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
[self.contentView addSubview:imageView];
_imageView = imageView;
}
return _imageView;
}
- (void)setImage:(UIImage *)image
{
_image = image;
self.imageView.image = image;
}
- (void)setupIndexPath:(NSIndexPath *)indexPath count:(NSInteger)pagesCount
{
if (indexPath.row == pagesCount - 1) {
// 最后一个cell
// 添加跳转按钮
self.startButton.hidden = NO;
}else{
self.startButton.hidden = YES;
}
}
@end