iOS简单实现引导页面

引导页面的代码.h

#import <UIKit/UIKit.h>

#import "leadimageViewController.h"

#define WIDTH self.view.frame.size.width

#define HEIGHT self.view.frame.size.height

@interface homeViewController : UIViewController<UIScrollViewDelegate>

 

@property(strong,nonatomic)UIScrollView *scollView;

@property(strong,nonatomic)UIImageView *image1;

@property(strong,nonatomic)UIImageView *image2;

@property(strong,nonatomic)UIImageView *image3;

@property(strong,nonatomic)UIImageView *image4;

@property(strong,nonatomic)UIPageControl *pagecontrol;

@property(strong,nonatomic)UIButton *button;

 

 

@end

 

 

用户ViewController.h的代码

#import "homeViewController.h"

 

@interface homeViewController ()

 

@end

 

@implementation homeViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    [self addimage];

    

}

 

-(void)addimage

{

    

    self.scollView=[[UIScrollView alloc] initWithFrame:self.view.frame];

    self.scollView.contentSize=CGSizeMake(4*WIDTH, HEIGHT);

    

    self.scollView.directionalLockEnabled=YES;

    self.scollView.pagingEnabled=NO;

    self.scollView.showsHorizontalScrollIndicator=NO;

    self.scollView.bounces=NO;

    [self.view addSubview:self.scollView];

    

    self.button=[[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 50)];

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

    self.button.backgroundColor=[UIColor grayColor];

    [self.button addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];

    [self.image4 addSubview:self.button];

    

    self.pagecontrol=[[UIPageControl alloc] init];

    CGSize pageSize=CGSizeMake(120, 44);

    self.pagecontrol.frame=CGRectMake((WIDTH-pageSize.width)*0.5, HEIGHT-pageSize.height-40, pageSize.width, pageSize.height);

    

    self.pagecontrol.backgroundColor=[UIColor clearColor];

    self.pagecontrol.numberOfPages=4;

    self.pagecontrol.currentPage=0;

    

    

    self.scollView.delegate=self;

    

    

    

    self.image1=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];

    self.image1.image=[UIImage imageNamed:@"1.jpg"];

    

    self.image2=[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, HEIGHT)];

    self.image2.image=[UIImage imageNamed:@"2.jpg"];

    

    self.image3=[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT)];

    self.image3.image=[UIImage imageNamed:@"3.jpg"];

    

    self.image4=[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH*3, 0, WIDTH, HEIGHT)];

    self.image4.image=[UIImage imageNamed:@"4.jpg"];

    

    [self.view addSubview:self.image1];

    [self.view addSubview:self.image2];

    [self.view addSubview:self.image3];

    [self.view addSubview:self.image4];

    

    

    self.image4.userInteractionEnabled=YES;

    

    

}

 

-(void)touch

{

    [self presentViewController:[leadimageViewController new] animated:YES completion:^{

        

    }];

}

 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    self.pagecontrol.currentPage=(int)(scrollView.contentOffset.x/WIDTH);

}

 

代理的代码appdelegate.m

 

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

    // Override point for customization after application launch.

    

    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])

    {

        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"firstLaunch"];

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

    //如果是第一次启动的话,使用homeViewController(用户引导页面) 作为根视图

    homeViewController *homeView=[[homeViewController alloc]init];

    self.window.rootViewController=homeView;

   }

   else

   {

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

    //如果不是第一次启动的话,使用leadimageViewController作为根视图

       leadimageViewController *leadimage=[[leadimageViewController alloc]init];

    self.window.rootViewController=leadimage;

    

    

   }

    self.window.backgroundColor=[UIColor whiteColor];

    [self.window makeKeyAndVisible];

 

 

 

    return YES;

}

 

代理的代码appdelegate.h

#import <UIKit/UIKit.h>

#import "leadimageViewController.h"

#import "homeViewController.h"

 

@interface AppDelegate : UIResponder <UIApplicationDelegate>

 

@property (strong, nonatomic) UIWindow *window;

@property(strong,nonatomic)leadimageViewController *leadimage;

 

 

@end

 

posted @ 2016-03-14 22:47  翌日晨曦  阅读(488)  评论(0编辑  收藏  举报