iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

时间:2022-01-08 03:32:32

首先创建一个引导图的控制器类

UserGuideViewController.h和UserGuideViewController.m

iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
#import <UIKit/UIKit.h>
#import "firstViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface UserGuideViewController : UIViewController<UIScrollViewDelegate> @end
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
#import "UserGuideViewController.h"

@interface UserGuideViewController ()
@property(strong,nonatomic)UIScrollView *scrollView;
@property(strong,nonatomic)UIPageControl *page;
@property(strong,nonatomic)UIImageView *image1;
@property(strong,nonatomic)UIImageView *image2;
@property(strong,nonatomic)UIImageView *image3;
@property(strong,nonatomic)UIButton *btn;
@end @implementation UserGuideViewController - (void)viewDidLoad {
[super viewDidLoad];
//加载用户引导图
[self initScroll]; }
-(void)initScroll{
self.image1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
self.image1.image=[UIImage imageNamed:@"1"]; self.image2=[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT)];
self.image2.image=[UIImage imageNamed:@"2"]; self.image3=[[UIImageView alloc]initWithFrame:CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT)];
self.image3.image=[UIImage imageNamed:@"3"]; self.scrollView=[[UIScrollView alloc]initWithFrame:self.view.frame];
self.scrollView.backgroundColor=[UIColor redColor];
self.scrollView.contentSize=CGSizeMake(WIDTH*3, HEIGHT); //锁定滚动方向
self.scrollView.directionalLockEnabled=YES;
//设置分页
self.scrollView.pagingEnabled=YES;
//隐藏滚动条
self.scrollView.showsHorizontalScrollIndicator=NO;
//设置是否回弹
self.scrollView.bounces=NO; //添加按钮
self.btn=[[UIButton alloc]initWithFrame:CGRectMake(80, 600, 230, 37)];
[self.btn setTitle:@"立即体验" forState:0];
self.btn.titleLabel.font=[UIFont boldSystemFontOfSize:20];
[self.btn setTitleColor:[UIColor colorWithRed:1.000 green:0.886 blue:0.107 alpha:1.000] forState:0];
self.btn.backgroundColor=[UIColor redColor];
[self.btn addTarget:self action:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside]; [self.image3 addSubview:self.btn]; //设置分页各个属性
self.page=[[UIPageControl alloc]init];
CGSize pageSize=CGSizeMake(120, 44);
self.page.frame=CGRectMake((WIDTH-pageSize.width)*0.5, HEIGHT-pageSize.height-40, pageSize.width, pageSize.height); self.page.backgroundColor=[UIColor clearColor];
//设置分页页数
self.page.numberOfPages=3;
self.page.currentPage=0; self.scrollView.delegate=self; [self.scrollView addSubview:self.image1];
[self.scrollView addSubview:self.image2];
[self.scrollView addSubview:self.image3]; [self.view addSubview:self.scrollView];
[self.view addSubview:self.page];
//打开用户交互,否则下面的button无法响应
self.image3.userInteractionEnabled=YES; }
//按钮的处罚时间
-(void)firstpressed{
//跳转至正文 [self presentViewController:[firstViewController new] animated:YES completion:^{ }];
} -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//设置分页 self.page.currentPage=(int)(scrollView.contentOffset.x/WIDTH);
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

正文页firstViewController.h和firstViewController.m

#import <UIKit/UIKit.h>

@interface firstViewController : UIViewController

@end
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
#import "firstViewController.h"
@interface firstViewController () @end @implementation firstViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor redColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

AppDelegate.mAppDelegate.h文件

iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
#import <UIKit/UIKit.h>
#import "firstViewController.h"
#import "UserGuideViewController.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property(strong,nonatomic)firstViewController *firstVc;
@property (strong, nonatomic) UIWindow *window; @end
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.firstVc=[[firstViewController alloc]init]; //判断应用是否是第一次启动
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];
NSLog(@"第一次启动");
//如果是第一次启动的话,使用UserGuideViewController(用户引导页面) 作为根视图
UserGuideViewController *userViewController=[[UserGuideViewController alloc]init];
self.window.rootViewController=userViewController;
}else{
NSLog(@"不是第一次启动");
//如果不是第一次启动的话,使用first作为根视图
firstViewController *first=[[firstViewController alloc]init];
self.window.rootViewController=first; }
self.window.backgroundColor=[UIColor whiteColor];
[self.window makeKeyAndVisible]; return YES;
} - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} - (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} - (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} @end
iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

运行效果

第一次运行

iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

第二次运行

iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults

iOS开发 首次启动显示用户引导,第二次启动直接进入App,UIScrollView,UIPageControl,NSUserDefaults的更多相关文章

  1. iOS开发之应用首次启动显示用户引导

    这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面  基本上都是使用UIScrollView 来实现, 新建一个继承于UIViewController ...

  2. iOS开发--应用设置及用户默认设置——转载

    [链接]iOS开发--应用设置及用户默认设置[1.bundlehttp://www.jianshu.com/p/6f2913f6b218 在iphone里面,应用都会在“设置”里面有个专属的应用设置, ...

  3. iOS-王云鹤 APP首次启动显示用户指导

    这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单 我们只需要在一个类里面写好用户引导页面  基本上都是使用UIScrollView 来实现, 新建一个继承于UIViewController ...

  4. iOS开发--应用设置及用户默认设置【2、读取应用中的设置】

            在上一节中,我们通过探讨应用的系统设置的基本功能,了解运用bundle捆绑包以及plist文件的基本开发.用户能够使用设置应用来声明他们的偏好设置,那么我们怎样去调用用户所设置的参数呢 ...

  5. IOS开发之自动布局显示网络请求内容

    在上一篇博客中详细的介绍了IOS开发中的相对布局和绝对布局,随着手机屏幕尺寸的改变,在App开发中为了适应不同尺寸的手机屏幕,用自动布局来完成我们想要实现的功能和效果显得尤为重要.本人更喜欢使用相对布 ...

  6. iOS开发——UI进阶篇(七)程序启动原理、打电话、发短信

    一.Info.plist常见的设置 1.建立一个工程后,会在Supporting files文件夹下看到一个“工程名-Info.plist”的文件,该文件对工程做一些运行期的配置,非常重要,不能删除 ...

  7. iOS开发证书都显示&OpenCurlyDoubleQuote;此证书的签发者无效”,更新WWDR Certificate证书后还是显示无效

    1.首先iOS开发证书显示"此证书的签发者无效".是因为WWDR Certificate证书过期导致的,须要更新WWDR Certificate证书! 1)下载最新WWDR Cer ...

  8. iOS开发之工具篇-20个可以帮你简化移动app开发流程的工具

    如果想进入移动app开发这个领域,你总能从别的开发者或者网上或者书上找到各种各样的方法和工具,对于新手来说,还没有摸清门路就已经陷入迷茫了.这里推荐20个可以帮你简化app开发流程的工具.很多开发者都 ...

  9. iOS开发--应用设置及用户默认设置【1、bundle的运用】

           在iphone里面,应用都会在“设置”里面有个专属的应用设置,选择该菜单界面,用户便可以在其中输入和更改各种选项,协助用户更便捷设置个人喜好与习惯. 在这一节中,希望能通过对捆绑包(bu ...

随机推荐

  1. linux下编译bib、tex生成pdf文件

    实验: 在linux环境下,编译(英文)*.bib和*.tex文件,生成pdf文件. 环境: fedora 20(uname -a : Linux localhost.localdomain 3.19 ...

  2. GY编辑平台产品总结

    产品亮点一.实时直播流的关键帧识别并展示选择频道的实时流并播放后,会在窗口中自动展示关键帧图片:配对选择关键帧的截图即确定了素材的入点,出点:编辑平台图如下所示:二.广告自动识别与监测方案1. 制作样 ...

  3. Java基础-布局

  4. 教你如何监控 Apache?

    什么是 Apache? Apache 是一款 HTTP 服务器软件,现在更名为 "http",而 Apache 则成了一个(包含httpd的项目)巨大的基金组织,根据习惯后文都用 ...

  5. Android滑动控件&period;md

    1.概述 最近写代码临时加了个功能主要是滑动选择的功能效果图如下: 2.代码 这里主要是用属性动画做的 <ImageButton android:id="@+id/fab" ...

  6. STL标准模板类

    STL,中文名标准模板库,是一套C++的标准模板类(是类!),包含一些模板类和函数,提供常用的算法和数据结构. STL分为:迭代器,容器,适配器,算法以及函数对象. --迭代器是一种检查容器内元素并遍 ...

  7. vue-cli 上传图片上传到OSS(阿里云)

    https://help.aliyun.com/document_detail/32068.html?spm=5176.doc32069.6.304.Qc4SUs(看) https://help.al ...

  8. make 命令【转】

    转自:https://www.ibm.com/support/knowledgecenter/zh/ssw_aix_71/com.ibm.aix.cmds3/make.htm#make__row-d3 ...

  9. 洛谷P1434 滑雪【记忆化搜索】

    题目:https://www.luogu.org/problemnew/show/P1434 题意: 给一个矩阵,矩阵中的数字代表海拔高度. 现在要找一条最长路径,使得路径上的海拔是递减的. 思路: ...

  10. Java之——利用Comparator接口对多个排序条件进行处理

    转载自:http://blog.csdn.net/l1028386804/article/details/56513205 膜拜大神··· 一.需求 假设现在有个如此的需求:需要对一个这样的雇员列表进 ...