ios开机启动引导页

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
    BOOL isOpen = [ud boolForKey:@"FirstRun"];
    if (!isOpen) {
        PageViewController *page = [PageViewController new];
        self.window.rootViewController = page;
        [ud setBool:YES forKey:@"FirstRun"];
        [ud synchronize];
        return YES;
    }
    
    return YES;
}

//
//  PageViewController.m
//  开机启动引导页
//
//  Created by Qianfeng on 15/10/18.
//  Copyright (c) 2015年 张向阳. All rights reserved.
//

#import "PageViewController.h"
#include "ViewController.h"

@interface PageViewController () <UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@end

@implementation PageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];
    [self createScrollView];

}
- (void)createScrollView {
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    for (NSInteger i = 0; i < 4; i++) {
        UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"32_%ld.jpg", i]];
        UIImageView *imgView = [[UIImageView alloc] initWithFrame: CGRectMake(i*_scrollView.bounds.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
        imgView.image = img;
        if (i==3) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.bounds = CGRectMake(100, 100, 100, 50);
            button.center = self.view.center;
            button.backgroundColor = [UIColor greenColor];
            [button setTitle:@"开始体验" forState:UIControlStateNormal];
            [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [imgView addSubview:button];
            imgView.userInteractionEnabled = YES; // 打开用户交互
        }
        [_scrollView addSubview:imgView];
    }
    _scrollView.contentSize = CGSizeMake(4*_scrollView.bounds.size.width, _scrollView.bounds.size.height);
    _scrollView.bounces = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.delegate = self;
    [self.view addSubview:_scrollView];
    [self createPageControl];
}

- (void)createPageControl {
    UIPageControl *pageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-30, self.view.bounds.size.width, 30)];
    pageControl.numberOfPages=4;
    pageControl.tag=301;
    [pageControl addTarget:self  action:@selector(pageClick:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:pageControl];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    UIPageControl *page=(UIPageControl *)[self.view viewWithTag:301];
    page.currentPage=scrollView.contentOffset.x/scrollView.bounds.size.width;
}
-(void)pageClick:(UIPageControl *)pageControl{
    [_scrollView setContentOffset:CGPointMake(pageControl.currentPage*_scrollView.bounds.size.width, 0) animated:YES];
    
}

- (void)btnClick:(UIButton *)senter {
    ViewController *vc = [ViewController new];
    [self presentViewController:vc animated:YES completion:nil];
}
@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值