zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

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

iosApp 用户 启动 显示 指导 首次
2023-09-27 14:23:53 时间

这个功能的重点就是在如何判断应用是第一次启动的. 其实很简单

我们只需要在一个类里面写好用户引导页面  基本上都是使用UIScrollView 来实现,

新建一个继承于UIViewController的类 命名为 UserGuideViewController ,

UserGuideViewController.m 写

 

- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColorredColor];

    [selfinitGuide];//加载新用户指导页面

}

-(void)initGuide{

    

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)];

    [scrollView setContentSize:CGSizeMake(1280, 0)];

    [scrollView setPagingEnabled:YES];  //视图整页显示

    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];

    [imageview setImage:[UIImage imageNamed:@"0.png"]];

    [scrollView addSubview:imageview];

    [imageview release];

    

    UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(320, 0, 320, 460)];

    [imageview1 setImage:[UIImage imageNamed:@"1.png"]];

    [scrollView addSubview:imageview1];

    [imageview1 release];

    

    UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(640, 0, 320, 460)];

    [imageview2 setImage:[UIImage imageNamed:@"2.png"]];

    [scrollView addSubview:imageview2];

    [imageview2 release];

    

    UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(960, 0, 320, 460)];

    [imageview3 setImage:[UIImage imageNamed:@"3.png"]];

    

    imageview3.userInteractionEnabled = YES;    //打开imageview3的用户交互;否则下面的button无法响应

    [scrollView addSubview:imageview3];

    [imageview3 release];

    

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];//imageview3上加载一个透明的button

    [button setTitle:@"立即体验" forState:UIControlStateNormal];

    [button setFrame:CGRectMake(46, 371, 230, 37)];

    [button addTarget:selfaction:@selector(firstpressed) forControlEvents:UIControlEventTouchUpInside];

    [imageview3 addSubview:button];

    [self.view addSubview:scrollView];

    [scrollView release];

    button.backgroundColor =[UIColorredColor];

}

//Button的方法  ViewController为 指导完之后 点击进入的主视图

- (void)firstpressed{

    [selfpresentModalViewController:[[[ViewControlleralloc] init] autorelease] animated:YES];  //点击button跳转到根视图s

}



----------------------------------------------------------

AppDelegate.m 中的代码  


 

#import "AppDelegate.h"


#import "ViewController.h"



@implementation AppDelegate


- (void)dealloc

{

    [_window release];

    //[_viewController release];

    [super dealloc];

}


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

{

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

    

    

    //判断是不是第一次启动

    if (![[NSUserDefaultsstandardUserDefaults]boolForKey:@"firstLaunch"]) {

        [[NSUserDefaultsstandardUserDefaults ]setBool:YESforKey:@"firstLaunch"];

        NSLog(@"第一次启动");

        //如果是第一次启动 使用UserGuideViewController

        UserGuideViewController *userGUideViewController =[[UserGuideViewControlleralloc]init];

        self.window.rootViewController =userGUideViewController;

        [userGUideViewController release];

        

    }

    else{

        NSLog(@"不是第一次启动");

        //如果不是第一次启动使用应用的的主视图

        ViewController *Vc = [[ViewControlleralloc] init];

                 self.window.rootViewController = Vc;

                [Vc release];

                

        

    }

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    return YES;


}