iOS首次启动程序引导图

简介: iOS首次启动程序引导图

iOS首次启动程序引导图


第一次运行一个程序时候,我们会看到新手引导页,就是程序引导图,除非后来版本升级,或者卸载软件后重装才会再次看到引导页

我们先来看效果:


65a37dc1d389e977ca3409c0a6f68fc2.jpg

Untit.gif


这里我第一次运行程序时候,直接是有引导图的,后来两次运行都没有再次出现引导图。除非下次版本更新之后,或者卸载再次运行程序才会出现引导图。

先给大家两张图片分析一下


51fb8e2a5f5dd72a573a9babc06ca240.png

Snip20160911_3.png


1d4dd6870a4bbe6257dd46266e6e4064.png

Snip20160911_2.png


现在来教一下大家如何用代码实现引导图

第一步:在AppDelegate.m文件中

ef804fe7dcc2e37c6971e6b1841b030d.png

Snip20160910_1.png


代码呈上

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // 1.创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    // 2.设置根控制器
    NSString *key = @"CFBundleVersion";
    // 上一次的使用版本(存储在沙盒中的版本号)
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    // 当前软件的版本号(从Info.plist中获得)
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
    if ([currentVersion isEqualToString:lastVersion]) { // 版本号相同:这次打开和上次打开的是同一个版本
        self.window.rootViewController = [[LYWTabBarViewController alloc] init];
    } else { // 这次打开的版本和上一次不一样,显示新特性
        self.window.rootViewController = [[LYWNewfeatureViewController alloc] init];
        // 将当前的版本号存进沙盒
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    // 3.显示窗口
    [self.window makeKeyAndVisible];
    return YES;
}
第二步:在LYWNewfeatureViewController.m 中实现简单的轮播图效果

#import "LYWNewfeatureViewController.h"
#import "LYWTabBarViewController.h"
#define NewfeatureCount 3
@interface LYWNewfeatureViewController ()<UIScrollViewDelegate>
@property (nonatomic,weak) UIPageControl *pageControl;
@end
@implementation LYWNewfeatureViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupScrollView];
}
//创建UIScrollView并添加图片
- (void)setupScrollView
{
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = [UIScreen mainScreen].bounds;
    [self.view addSubview:scrollView];
    scrollView.bounces = NO;
    scrollView.pagingEnabled = YES;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.contentSize = CGSizeMake(3*kScreenWidth, 0);
    scrollView.delegate = self;
    for (NSInteger i = 0; i < NewfeatureCount; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.x = i * kScreenWidth;
        imageView.y = 0;
        imageView.width = kScreenWidth;
        imageView.height = kScreenHeight;
        NSString *name = [NSString stringWithFormat:@"f%ld-5",i+1];
        imageView.image = [UIImage imageNamed:name];
        [scrollView addSubview:imageView];
        if (i == NewfeatureCount - 1) {
            [self setupStartBtn:imageView];
        }
    }
    // 4.添加pageControl:分页,展示目前看的是第几页
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.numberOfPages = NewfeatureCount;
    pageControl.backgroundColor = [UIColor redColor];
    pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
    pageControl.pageIndicatorTintColor = KRGB(189, 189, 189);
    pageControl.centerX = kScreenWidth * 0.5;
    pageControl.centerY = kScreenHeight - 50;
    [self.view addSubview:pageControl];
    self.pageControl = pageControl;
}
//左上角的灰色跳过按钮
-(void)createSkipBt
{
    UIButton *skipBt = [UIButton buttonWithType:UIButtonTypeCustom];
    skipBt.frame = CGRectMake(kScreenWidth - 90, 40, 80, 30);
    skipBt.backgroundColor = [UIColor colorWithRed:0.3 green:0.3f blue:0.3f alpha:0.3];
    [skipBt setTitle:@"跳过" forState:UIControlStateNormal];
    [skipBt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    skipBt.layer.cornerRadius = 10;
    skipBt.clipsToBounds = YES;
    skipBt.tag = 10;
    [skipBt addTarget:self action:@selector(BtnDidClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:skipBt];
}
//手动拖拽结束时候调用
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    double page = scrollView.contentOffset.x / scrollView.width;
    // 四舍五入计算出页码
    self.pageControl.currentPage = (int)(page + 0.5);
    // 1.3四舍五入 1.3 + 0.5 = 1.8 强转为整数(int)1.8= 1
    // 1.5四舍五入 1.5 + 0.5 = 2.0 强转为整数(int)2.0= 2
    // 1.6四舍五入 1.6 + 0.5 = 2.1 强转为整数(int)2.1= 2
    // 0.7四舍五入 0.7 + 0.5 = 1.2 强转为整数(int)1.2= 1
}
//给最后一张图片添加 进入问医生按钮
- (void)setupStartBtn:(UIImageView *)imgView
{
    imgView.userInteractionEnabled = YES;
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:@"cancel_ask"] forState:UIControlStateNormal];
    btn.size = btn.currentBackgroundImage.size;
    btn.centerX = imgView.width * 0.5;
    btn.centerY = imgView.height * 0.75;
    [btn setTitle:@"进入问医生" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(BtnDidClicked) forControlEvents:UIControlEventTouchUpInside];
    [imgView addSubview:btn];
}
//进入问医生按钮点击事件
-(void)BtnDidClicked
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    window.rootViewController = [[LYWTabBarViewController alloc] init];
}
@end

这样就👌了,其实很简单,不过是最近一个外包项目过来,然后我接手了,给它做一了一个启动引导图,闲来没事,就写写这片文章打法自己无聊的时间,也方便很多初学者学习

相关文章
|
2月前
|
存储 运维 安全
iOS加固原理与常见措施:保护移动应用程序安全的利器
iOS加固原理与常见措施:保护移动应用程序安全的利器
31 0
|
4月前
|
存储 运维 安全
iOS加固原理与常见措施:保护移动应用程序安全的利器
iOS加固原理与常见措施:保护移动应用程序安全的利器
40 0
|
4月前
|
监控 测试技术 iOS开发
查看ios 应用程序性能
查看ios 应用程序性能
37 0
|
2月前
|
iOS开发 开发者
iOS移动应用程序的备案与SHA-1值查看
iOS移动应用程序的备案与SHA-1值查看
41 2
|
3月前
|
iOS开发 开发者 索引
批量上传 iOS 应用程序截图的实用技巧
批量上传 iOS 应用程序截图的实用技巧
|
4月前
|
JSON JavaScript 安全
iOS 应用程序数据保护:如何保护 iOS 应用程序中的图片、资源和敏感数据
iOS 应用程序数据保护:如何保护 iOS 应用程序中的图片、资源和敏感数据
|
4月前
|
iOS开发 开发者
iOS移动应用程序的备案与SHA-1值查看
iOS移动应用程序的备案与SHA-1值查看
44 0
|
4月前
|
安全 Java 数据安全/隐私保护
Android和iOS应用程序加固方法详解:混淆、加壳、数据加密、动态加载和数字签名实现
Android和iOS应用程序加固方法详解:混淆、加壳、数据加密、动态加载和数字签名实现
78 0
|
5月前
|
iOS开发 开发者
📝iOS移动应用程序的备案与SHA-1值查看
在开发和发布移动应用程序时,进行App备案是非常重要的一步,它是确保您的应用在合规性方面符合相关法规的过程。同时,对于一些需要与第三方服务进行集成的情况,查看应用的SHA-1值也是必要的。本篇博客将向您展示如何进行iOS移动应用程序的备案,并查看SHA-1值。
|
6月前
|
运维 安全 数据安全/隐私保护
iOS加固原理与常见措施:保护移动应用程序安全的利器
随着移动应用的普及和用户对数据安全的关注度提高,iOS加固成为了很多开发者和企业的必备工具。那么,iOS加固是如何保护应用程序的安全性的呢? iOS加固是指对OS应用程序进行一系列的安全措施,以提高其抗逆向工程、反编译和破解的能力。下面将介绍iOS加固的原理和常见的加固措施。
iOS加固原理与常见措施:保护移动应用程序安全的利器