IOS笔记UI--首次启动介绍和LaunchDemo

申明:此为本人学习笔记,若有纰漏错误之处的可留言共同探讨


制作首次启动介绍app和Launch的效果,主要是通过在appDelegate里判断是不是第一次登陆该app,如果是,就将根视图赋给首次启动的那个VC(ViewController),如果不是就将根视图赋给launchVC。

/*
首次启动介绍和Launch思路
1.在appDelegate里,通过NSUserDefaults判断是不是第一次启动,如果是,把根视图给first;反之则把根视图赋给launch
2.在first首次启动介绍app这个VC里面呢。创建一个scrollVIew。需要几个介绍页面就创建几个UIImageView,然后在最后一个UIimageView加上手势,点击跳转到主视图
3.在launchVC里,使用performSelector这个方法,延时需要的时间长度,然后跳回主视图即可


*/

代码部分:

appDelegate判断部分

 if (![[NSUserDefaults standardUserDefaults]boolForKey:@"first"]) {
        // the first
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"first"];
        self.window.rootViewController = [[FLViewController alloc]init];
    } else {
        // not first
        self.window.rootViewController = [[LaunchViewController alloc]init];
    }

firstVC部分
#define MY_SCREEN_WIDTH self.view.bounds.size.width
#define MY_SCREEN_HEIGHT self.view.bounds.size.height
#define SCROLLVIEW_PAGE_NUMBER 4
#define ARC4RANDOM [UIColor colorWithRed:arc4random()%256/255. green:arc4random()%256/255. blue:arc4random()%256/255. alpha:1]

@interface FLViewController ()<UIScrollViewDelegate>

@end

@implementation FLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // ScrollView
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.frame];
    scrollView.contentSize = CGSizeMake(MY_SCREEN_WIDTH*SCROLLVIEW_PAGE_NUMBER,MY_SCREEN_WIDTH);
    [self.view addSubview:scrollView];
    scrollView.pagingEnabled = YES;
    scrollView.contentOffset =CGPointMake(0, 0);
    scrollView.showsHorizontalScrollIndicator =NO;
    scrollView.delegate = self;
    scrollView.bounces = NO;
    
    UIImageView *imageView;
    for (int i = 0 ; i<SCROLLVIEW_PAGE_NUMBER; i++) {
      imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i*375, 0, MY_SCREEN_WIDTH, MY_SCREEN_HEIGHT)];
        imageView.backgroundColor = ARC4RANDOM;
        [scrollView addSubview:imageView];
        imageView.tag = 1+i;
    }

    [imageView setUserInteractionEnabled:YES];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(gotoMain:)];
    [[self.view viewWithTag:SCROLLVIEW_PAGE_NUMBER] addGestureRecognizer:tap];
    
}
#pragma mark - UITapGestureRecognizer
-(void)gotoMain:(UITapGestureRecognizer *)tap {
    ViewController *view = [[ViewController alloc]init];
    [self presentViewController:view animated:NO completion:nil];
}
launchVC部分

#import "LaunchViewController.h"
#import "ViewController.h"
@interface LaunchViewController ()

@end

@implementation LaunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:imageView];
    UIImage *image = [UIImage imageNamed:@"myPic.jpg"];
    imageView.image = image;
    [self performSelector:@selector(gotoMain) withObject:self afterDelay:1.5];
}

#pragma mark - 
-(void)gotoMain {
    ViewController *mainVC = [[ViewController alloc]init];
    [self presentViewController:mainVC animated:NO completion:nil];
}



附上本人完整Demo:http://download.csdn.net/detail/csdn_hhg/9207599
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值