ios - Guide(新手引导)页

AppDelegate.h

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "ViewController.h"
#import "HelperViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (readonly, strong) NSPersistentContainer *persistentContainer;

- (void)saveContext;

@property (nonatomic,strong)HelperViewController *vc;
@property (nonatomic,strong)UITabBarController *tabBarCtl;//标签栏控制器

@end

AppDelegate.m

#import "AppDelegate.h"
#import "GuideViewController.h"//Guide

#import "MyViewController.h"//小说
@interface AppDelegate ()

@end

@implementation AppDelegate

//私有方法,用于生成一个导航控制器
- (UINavigationController *)createNavigationWithController:(UIViewController *)vc title:(NSString *)title image:(NSString *)imgName selectImage:(NSString *)selectImgName{

    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    vc.navigationItem.title = title;
    nav.tabBarItem = [[UITabBarItem alloc]initWithTitle:title image:[UIImage imageNamed:imgName] selectedImage:[UIImage imageNamed:selectImgName]];


    return nav;
}


//标签栏控制器
- (UITabBarController *)tabBarCtl{
    if (!_tabBarCtl) {
        _tabBarCtl = [[UITabBarController alloc]init];
        self.tabBarCtl.tabBar.tintColor = [UIColor blackColor];
        UINavigationController *homeNav = [self createNavigationWithController:[[HelperViewController alloc]init] title:@"挑战" image:@"main_bottom_tab_recipe_gray_25x25_" selectImage:@"main_bottom_tab_recipe_red_25x25_"];
        UINavigationController *selectNav = [self createNavigationWithController:[[MyViewController alloc]init] title:@"我的" image:@"main_bottom_tab_pai_gray_25x25_" selectImage:@"main_bottom_tab_pai_red_25x25_"];


        _tabBarCtl.viewControllers = @[homeNav,selectNav];

        [[UITabBar appearance] setTintColor:[UIColor colorWithRed:252/255.0  green:104/255.0  blue:106/255.0 alpha:1]];

        //设置导航的背景颜色
        [UINavigationBar appearance].barTintColor=[UIColor colorWithRed:252/255.0  green:104/255.0  blue:106/255.0 alpha:1];




    }
    return _tabBarCtl;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.



    GuideViewController *guideVC = [[GuideViewController alloc]init];
    self.vc = [[HelperViewController alloc]init];
    //第一次运行app
    if (![[NSUserDefaults standardUserDefaults]objectForKey:NOT_FIRST_LANUCH]) {
        self.window.rootViewController = guideVC;
    }
    //非首次运行app
    else{
        //获取当前的版本号

        //获取持久化的版本号数据
        NSString *savedVersion =  [[NSUserDefaults standardUserDefaults]objectForKey:NOT_FIRST_LANUCH];
        //判断版本号是否一致
        if ([savedVersion isEqualToString:VERSION_CURRENT]) {
            //没有更新
            self.window.rootViewController = self.vc;
        }
        else{
            //更新了
            self.window.rootViewController = guideVC;
        }
    }


    return YES;
}

Header.pch

#ifndef Header_pch
#define Header_pch

#import "AppDelegate.h"
#define App_Delegate (AppDelegate *)[UIApplication sharedApplication].delegate

/*
 系统版本号
 */
#define VERSION_10_0   [UIDevice currentDevice].systemVersion.doubleValue >= 10.0
#define VERSION_9_0    [UIDevice currentDevice].systemVersion.doubleValue >= 9.0
/*
 用于适配的宏
 */
#define SCR_W [UIScreen mainScreen].bounds.size.width
#define SCR_H [UIScreen mainScreen].bounds.size.height
//适配x轴的宏
#define FIT_X(w) (SCR_W / 375. *(w))
//适配Y轴的宏
#define FIT_Y(h) (SCR_H / 667. *(h))
/*
 当前app版本号的宏
 */
#define VERSION_CURRENT [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"]
//持久化当前版本号的key的宏
#define NOT_FIRST_LANUCH @"NotFirstLanuch"


/*
 Doucuments目录的宏
 */
#define DOCUMENT_PATH [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]

// Include any system framework and library headers here that should be included in all compilation units.
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.

#endif /* Header_pch */

HelperViewController.m


    AppDelegate *app = App_Delegate;
    app.window.rootViewController = app.tabBarCtl;
UIBarButtonItem *button =[[UIBarButtonItem alloc]initWithTitle:@"求帮助" style:UIBarButtonItemStyleDone target:self action:@selector(closeConversation:)];
    self.navigationItem.rightBarButtonItem = button;

self.title = @"乐于助人";

GuideViewController.m

#import "GuideViewController.h"
#import "ImageScrollView.h"
#import "AppDelegate.h"
@interface GuideViewController ()<ImageScrollViewDelegate>


@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    NSArray *imgArr = @[@"1.jpg",@"3.jpg",@"2.jpg"];
    ImageScrollView *imgScrView  = [[ImageScrollView alloc]initWithFrame:CGRectNull style:ImageScrollType_Guide images:imgArr confirmBtnTitle:@"立即体验" confirmBtnTitleColor:[UIColor redColor] confirmBtnFrame:CGRectMake(230, 620, 100, 40) autoScrollTimeInterval:0 delegate:self];


    [self.view addSubview:imgScrView];
    [imgScrView addPageControlToSuperView:self.view];



}

#pragma mark -ImageScrollViewDelegate
- (void)experienceDidHandle{
    //获取当前的版本号,持久化
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    [ud setObject:VERSION_CURRENT forKey:NOT_FIRST_LANUCH];
    [ud synchronize];

    //切换窗口的根视图控制器
    AppDelegate *app = App_Delegate;
    app.window.rootViewController = app.vc;

}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值