iOS现成的引导页面的实现:纯代码

首先创建继承于UIView的GuidePageView.h和GuidePageView.m

 

// GuidePageView.h

// ProgramGuidePage

 

#import <UIKit/UIKit.h>

 

@interface GuidePageView : UIView

 

- (id)initWithImages:(NSArray *)images;

 

@end

 

// GuidePageView.m

// ProgramGuidePage

 

 

#define kKEY_WINDOW [[UIApplication sharedApplication]keyWindow]

 

#import "GuidePageView.h"

 

@interface GuidePageView ()

 

@property (nonatomic, retain) UIScrollView * grideScroll;

 

@end

 

 

 

@implementation GuidePageView

 

 

 

- (id)initWithImages:(NSArray *)images

{

    self = [superinitWithFrame:kKEY_WINDOW.bounds];

    if (self)

    {

       [kKEY_WINDOW addSubview:self];

       

       self.grideScroll = [[UIScrollView alloc] initWithFrame:self.bounds];

       self.grideScroll.contentSize = CGSizeMake(kKEY_WINDOW.frame.size.width *images.count, kKEY_WINDOW.frame.size.height);

       self.grideScroll.bounces = NO;

        self.grideScroll.pagingEnabled= YES;

        [selfaddSubview:self.grideScroll];

       [self.grideScroll release];

       

        [selfloadImagesWithArray:images];

    }

    return self;

}

 

 

 

- (void)loadImagesWithArray:(NSArray *)items

{

    for (int i =0; i < items.count; i++)

    {

       UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * kKEY_WINDOW.frame.size.width, 0,kKEY_WINDOW.frame.size.width, kKEY_WINDOW.frame.size.height)];

       imageView.userInteractionEnabled = YES;

       imageView.image = [UIImage imageNamed:[items objectAtIndex:i]];

       [self.grideScroll addSubview:imageView];

       

        if (i ==items.count - 1) {

           UIButton * but = [UIButton buttonWithType:UIButtonTypeSystem];

           but.frame = CGRectMake(120,

                                  kKEY_WINDOW.frame.size.height - 100,

                                  kKEY_WINDOW.frame.size.width - 240,

                                   40);

           but.layer.cornerRadius = 4;

           but.backgroundColor = [UIColor grayColor];

            [butsetTitle:@"进入体验" forState:UIControlStateNormal];

            [butaddTarget:self action:@selector(beginExperience:)forControlEvents:UIControlEventTouchUpInside];

            [imageView addSubview:but];

        }

    }

}

 

 

- (void)beginExperience:(UIButton *)sender

{

    [UIViewanimateWithDuration:.3

                    animations:^{

                        self.frame = CGRectMake(self.frame.origin.x,

                                                [UIScreen mainScreen].bounds.size.height,

                                                self.frame.size.width,

                                                self.frame.size.height);

                        

                    }

                    completion:^(BOOL finished) {

                        [self removeFromSuperview];

                        

                    }];   

}

@end

 

 

在AppDelegate.m里引入头文件#import "GuidePageView.h",写入一下代码,用将引导面所需要的图片写入数组内:

 

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

        NSArray*array = @[@"one.jpg",

                          @"two.jpg",

                          @"three.jpg",

                          @"four.jpg"];

       GuidePageView *guide = [[GuidePageView alloc]initWithImages:array];

       [[NSUserDefaults standardUserDefaults] setBool:YESforKey:@"firstRun"];

    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值