#import "ViewController.h"
#import "FirstTimeLoadJudge.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//取对应的Key (记录用户打开app次数)的整型值,直接加1
[FirstTimeLoadJudge recordAppOpenTimes];
//基本设置:先进入ViewController中
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewController *view = [[ViewController alloc]init];
self.window.rootViewController = view;
[self.window makeKeyWindow];
return YES;
}
//FirstTimeLoadJudge中的类方法
@interface FirstTimeLoadJudge : NSObject
// 记录应用程序的打开次数
+ (void)recordAppOpenTimes;
//返回应用程序的打开次数
+ (NSInteger)appOpenTimes;
//是否是第一次打开应用程序
+ (BOOL)isFirstTimeOpenAPP;
@end
#import "FirstTimeLoadJudge.h"
#define kAppOpenTimes @"kAppOpenTimes"
@implementation FirstTimeLoadJudge
//记录应用打开次数
+ (void)recordAppOpenTimes{
//取出打开次数
NSInteger times = [[NSUserDefaults standardUserDefaults]integerForKey:kAppOpenTimes];
//每打开一次次数+1
times++;
//将当前次数写入其中
[[NSUserDefaults standardUserDefaults]setInteger:times forKey:kAppOpenTimes];
}
//查看应用打开的次数
+ (NSInteger)appOpenTimes{
return [[NSUserDefaults standardUserDefaults]integerForKey:kAppOpenTimes];
}
//是否是第一次打开应用程序
+ (BOOL)isFirstTimeOpenAPP{
if ([FirstTimeLoadJudge appOpenTimes] == 1) {
return YES;
}else{
return NO;
}
}
//ViewController中实现功能
#import "ViewController.h"
#import "FirstTimeLoadJudge.h"
#import "RootViewController.h"
#import "AppDelegate.h"
#define VIEW_WIDTH [[UIScreen mainScreen] bounds].size.width
#define VIEW_HEIGHT [[UIScreen mainScreen] bounds].size.height
@interface ViewController ()
@property (nonatomic,strong)UIScrollView *scrollView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor blueColor];
//判断应用程序是否是第一次打开 如果是第一次打开
if ([FirstTimeLoadJudge isFirstTimeOpenAPP]) {
NSLog(@"用户第一次打开应用程序");
//显示新特性界面
[self showNewFunction];
}else{//不是第一次打开
//切换Window的根视图控制器
RootViewController *root = [[RootViewController alloc]init];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.window.rootViewController = root;
}
}
- (void)showNewFunction{
NSLog(@"显示导图界面");
//准备5张图片
NSArray *imageArray = @[@"helpphoto_one",@"helpphoto_two",@"helpphoto_three",@"helpphoto_four",@"helpphoto_five"];
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT)];
[self.view addSubview:self.scrollView];
//图片的个数
NSInteger imageCount = imageArray.count;
//内容尺寸
self.scrollView.contentSize = CGSizeMake(VIEW_WIDTH * imageCount, VIEW_HEIGHT);
//按页滚动
self.scrollView.pagingEnabled = YES;
self.scrollView.bounces = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
//往scrollView上添加图片
for (NSInteger i = 0; i < imageCount; i++ ) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * VIEW_WIDTH, 0, VIEW_WIDTH, VIEW_HEIGHT)];
NSString *imageName = imageArray[i];
//如果是网络图片
//[imageView sd_setImageWithURL:[NSURL URLWithString:imageName] placeholderImage:[UIImage imageNamed:@""]];
//本地图片
imageView.image = [UIImage imageNamed:imageName];
if (i == imageCount - 1) {
imageView.userInteractionEnabled = YES;
//在最后一张图片上添加一个进入主界面的按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(120, 50, 100, 50);
[btn setTitle:@"开始体验" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
btn.backgroundColor = [UIColor purpleColor];
[btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
}
//滚动视图上添加imageView
[self.scrollView addSubview:imageView];
}
}
- (void)btnPressed:(UIButton *)btn{
RootViewController *root = [[RootViewController alloc]init];
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//切换根视图控制器
appDelegate.window.rootViewController = root;
}
// RootViewController为导图进入后的主界面内容