应用首次启动引入导图

#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为导图进入后的主界面内容

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值