iOS应用首次启动引入导图

释放双眼,带上耳机,听听看~!
#import "ViewController.h"

#import "FirstTimeLoadJudge.h"

@interface
AppDelegate ()

@end

@implementation AppDelegate




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {

   
//取对应的Key (记录用户打开app次数)的整型值,直接加1

    [FirstTimeLoadJudgerecordAppOpenTimes];

    //基本设置:先进入ViewController中

    self.window = [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

    self.window.backgroundColor
= [UIColorwhiteColor];

    ViewController *view = [[ViewControlleralloc]init];

    self.window.rootViewController
= view;

    [self.windowmakeKeyWindow];

    returnYES;

}




//FirstTimeLoadJudge中的类方法

@interface FirstTimeLoadJudge :
NSObject

// 记录应用程序的打开次数

+ (void)recordAppOpenTimes;

//返回应用程序的打开次数

+ (NSInteger)appOpenTimes;

//是否是第一次打开应用程序

+ (BOOL)isFirstTimeOpenAPP;




@end




#import "FirstTimeLoadJudge.h"




#define kAppOpenTimes @"kAppOpenTimes"




@implementation FirstTimeLoadJudge

//记录应用打开次数

+ (void)recordAppOpenTimes{

    //取出打开次数

    NSInteger times = [[NSUserDefaultsstandardUserDefaults]integerForKey:kAppOpenTimes];

   
//每打开一次次数+1

    times++;

   
//将当前次数写入其中

    [[NSUserDefaultsstandardUserDefaults]setInteger:times
forKey:kAppOpenTimes];

}

//查看应用打开的次数

+ (NSInteger)appOpenTimes{

    return [[NSUserDefaultsstandardUserDefaults]integerForKey:kAppOpenTimes];

}

//是否是第一次打开应用程序

+ (BOOL)isFirstTimeOpenAPP{

    if ([FirstTimeLoadJudgeappOpenTimes] ==
1) {

        returnYES;

    }else{

        returnNO;

    }

}




//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 {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColorblueColor];

    

   
//判断应用程序是否是第一次打开如果是第一次打开

    if ([FirstTimeLoadJudgeisFirstTimeOpenAPP]) {

        NSLog(@"用户第一次打开应用程序");

        //显示新特性界面

        [selfshowNewFunction];

    }else{//不是第一次打开

        //切换Window的根视图控制器

        RootViewController *root = [[RootViewControlleralloc]init];

        AppDelegate *appDelegate = (AppDelegate *)[UIApplicationsharedApplication].delegate;

        appDelegate.window.rootViewController = root;

    }

}

- (void)showNewFunction{

    NSLog(@"显示导图界面");

    //准备5张图片

    NSArray *imageArray =
@[@"helpphoto_one",@"helpphoto_two",@"helpphoto_three",@"helpphoto_four",@"helpphoto_five"];

    self.scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,
0, VIEW_WIDTH,
VIEW_HEIGHT)];

    [self.viewaddSubview: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 = [[UIImageViewalloc]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 = [UIImageimageNamed:imageName];

        if (i == imageCount -
1) {

            imageView.userInteractionEnabled =
YES;


//在最后一张图片上添加一个进入主界面的按钮

            UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

            btn.frame =
CGRectMake(120,
50, 100,
50);

            [btn setTitle:@"开始体验"forState:UIControlStateNormal];

            [btn setTitleColor:[UIColoryellowColor] forState:UIControlStateNormal];

            btn.backgroundColor = [UIColorpurpleColor];

            [btn addTarget:selfaction:@selector(btnPressed:)
forControlEvents:UIControlEventTouchUpInside];

            [imageView addSubview:btn];

        }

        //滚动视图上添加imageView

        [self.scrollViewaddSubview:imageView];

    }

}

- (void)btnPressed:(UIButton *)btn{

    RootViewController *root = [[RootViewControlleralloc]init];

    AppDelegate *appDelegate = (AppDelegate *)[UIApplicationsharedApplication].delegate;

   
//切换根视图控制器

    appDelegate.window.rootViewController = root;

}




// RootViewController为导图进入后的主界面内容


 

人已赞赏
iOS文章

iOS 延迟执行的几种方式

2020-2-26 17:21:39

iOS文章

Swift--09枚举类型

2020-2-26 18:30:32

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索