iOS引导页的快速引用

  • 1.引入MQGuideView文件,根据需要修改引导页数量和图片名称
static const NSInteger NumberOfGuide = 3; //引导页数
 //修改图片名称
imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"default_%d",i+1]];

  • 2.在首页进行登录判断,是否是第一次打开App,并存入本地。初始化MQGuideView,加到当前视图页面,具体在哪里添加随个人喜好,这里只做简单演示。
- (void)viewWillAppear:(BOOL)animated{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isFirstLaunch"]) {
        _isFirstLaunch = YES;
        [[NSUserDefaults standardUserDefaults] setBool:_isFirstLaunch forKey:@"isFirstLaunch"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        _guideView = [[MQGuideView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        _guideView.delegate = self;
        [self.view addSubview:_guideView];
    }
}
  • 3.添加代理事件,来控制引导页的跳转,这里做了个简单的动画
- (void)onPassButtonPressed{
    [UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
       _guideView.alpha = 0;
    } completion:^(BOOL finished) {
        [_guideView removeFromSuperview];
    }];
}

下面是.h和.m文件

.h文件
@protocol MQGuideViewDelegate 
//代理方法 跳过引导页
-(void)onPassButtonPressed;
@end


@interface MQGuideView : UIView
@property (nonatomic,weak)  id delegate;
@end

.m文件
@interface MQGuideView () 
@property (nonatomic, strong) UIPageControl *pageControl;
@end

@implementation MQGuideView

static const NSInteger NumberOfGuide = 3; //引导页数

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
        CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
        UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, screenW, screenH)];
        [self addSubview:scrollView];
        
        UIButton *passBtn = [[UIButton alloc]initWithFrame:CGRectMake(screenW-70.0f, 40.0f, 50.0f, 30.0f)];
        [passBtn addTarget:self action:@selector(onFinishedIntroButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        [passBtn setImage:[UIImage imageNamed:@"default_pass"] forState:UIControlStateNormal];
        [self addSubview:passBtn];
        
        scrollView.delegate = self;
        scrollView.backgroundColor = [UIColor whiteColor];
        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.showsVerticalScrollIndicator = NO;
        scrollView.contentSize = CGSizeMake(screenW*NumberOfGuide, screenH);
        scrollView.pagingEnabled = YES;
        for (int i=0; i

github链接 https://github.com/zmqFlyer/MQGuideView/tree/master

你可能感兴趣的:(iOS引导页的快速引用)