iOS 开发之应用首次启动显示用户引导
来源:互联网 发布:mac 139邮彩云同步盘 编辑:程序博客网 时间:2024/06/11 03:31
这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单
我们只需要在一个类里面写好用户引导页面 基本上都是使用UIScrollView 来实现,
新建一个继承于UIViewController的类 命名为 UserGuideViewController ,
在UserGuideViewController.m 写
1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 // Do any additional setup after loading the view. 5 self.view.backgroundColor = [UIColor redColor]; 6 7 [self initGuide]; //加载新用户指导页面 8 } 9 10 - (void)initGuide11 {12 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)];13 [scrollView setContentSize:CGSizeMake(1280, 0)];14 [scrollView setPagingEnabled:YES]; //视图整页显示15 // [scrollView setBounces:NO]; //避免弹跳效果,避免把根视图露出来16 17 UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];18 [imageview setImage:[UIImage imageNamed:@"0.png"]];19 [scrollView addSubview:imageview];20 [imageview release];21 22 UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];23 [imageview1 setImage:[UIImage imageNamed:@"1.png"]];24 [scrollView addSubview:imageview1];25 [imageview1 release];26 27 UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(640, 0, 320, 460)];28 [imageview2 setImage:[UIImage imageNamed:@"2.png"]];29 [scrollView addSubview:imageview2];30 [imageview2 release];31 32 UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(960, 0, 320, 460)];33 [imageview3 setImage:[UIImage imageNamed:@"3.png"]];34 imageview3.userInteractionEnabled = YES; //打开imageview3的用户交互;否则下面的button无法响应35 [scrollView addSubview:imageview3];36 [imageview3 release];37 38 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//在imageview3上加载一个透明的button39 [button setTitle:nil forState:UIControlStateNormal];40 [button setFrame:CGRectMake(46, 371, 230, 37)];41 [button addTarget:self action:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside];42 [imageview3 addSubview:button];43 44 [self.view addSubview:scrollView];45 [scrollView release];46 }
button的方法
1 - (void)firstpressed2 {3 [self presentModalViewController:[[[WeiBoViewController alloc] init] autorelease] animated:YES]; //点击button跳转到根视图4 }
至于添加button是因为我的用户引导最后一个页面有一个画上去的button,写着 开始使用 我在上面添加一个透明的button 用以实现调用方法
打开AppDelegate.m
首先引入头文件
1 #import "UserGuideViewController.h"2 #import "WeiBoViewController.h"
WeiBoViewController是我的根视图
application: didFinishLaunchingWithOptions: 方法内进行判断
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2 { 3 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 4 // Override point for customization after application launch. 5 6 //判断是不是第一次启动应用 7 if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) 8 { 9 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];10 NSLog(@"第一次启动"); 11 //如果是第一次启动的话,使用UserGuideViewController (用户引导页面) 作为根视图12 UserGuideViewController *userGuideViewController = [[UserGuideViewController alloc] init];13 self.window.rootViewController = userGuideViewController;14 [userGuideViewController release];15 }16 else17 {18 NSLog(@"不是第一次启动");19 //如果不是第一次启动的话,使用LoginViewController作为根视图20 WeiBoViewController *weiBoViewController = [[WeiBoViewController alloc] init];21 self.window.rootViewController = weiBoViewController;22 [weiBoViewController release];23 24 }25 26 self.window.backgroundColor = [UIColor whiteColor];27 [self.window makeKeyAndVisible];28 return YES;29 }
这样,就可以实现第一次打开应用显示用户引导 之后不再显示
- iOS 开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导
- iOS开发笔记--应用首次启动显示用户引导
- iOS开发笔记--应用首次启动显示用户引导
- iOS开发之应用首次启动显示用户引导 - 疯狂的萝卜 - 博客园
- iOS--应用首次启动的引导页
- iOS-王云鹤 APP首次启动显示用户指导
- IOS开发之程序首次启动时加载关于程序应用的简介
- IOS开发之程序首次启动时加载关于程序应用的简介
- IOS开发(二)之程序首次启动时加载关于程序应用的简介
- java.lang.OutOfMemoryError
- Hibernate中使用HQL的基础语法
- 遇到一个简单漏洞(sql注入)
- ubuntu 查找历史命令
- xcode的other linker flag的含义
- iOS 开发之应用首次启动显示用户引导
- hibernate Restrictions用法
- vim简单配置
- no such partition grub rescue的解决方案
- 黑马程序员-java 银行业务调度系统
- Java 注解学习
- php apache
- ios版本兼容问题
- C语言中宏定义转换字节序方法