iOS引导页

我这里是的引导页是viewController

#import <UIKit/UIKit.h>

我这里是将图片都加到了一个bundle的文件里
#define GET_IMAGE_FROM_BUNDLE_PATH(imageName,bundleName) [ResBundleUtils imageNamedFromImagesBundlePNG:imageName withSubPath:bundleName]

//适配3.5寸屏和4寸品的图片名
#define ADAPT_IMAGE_NAME(imageName) (IS_IPHONE_568 ? [NSString stringWithFormat:@"%@-568h", [imageName stringByDeletingPathExtension]]:imageName)


@protocol  UseGuideDelegate <NSObject>

-(void)removeGuideView;

@end

@interface  UseGuideViewController : UIViewController
{
    int currentPage;
    UIPageControl *pageControl;
    UIImageView *guideView;
}
@property(assign,nonatomic) id<UseGuideDelegate> delegate;

@end

实现文件



#import "UseGuideViewController.h"


@interface UseGuideViewController () <UIScrollViewDelegate>

@end

@implementation UseGuideViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self initWithGuideView];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

}
/**
 *  scrollView
 */
-(void)initWithGuideView
{
    UIScrollView * scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
    
    scroll.showsHorizontalScrollIndicator = NO;
    scroll.showsVerticalScrollIndicator = NO;
    scroll.backgroundColor=[UIColor clearColor];
    scroll.bounces = NO;
    scroll.delegate=self;
    scroll.pagingEnabled = YES;
    scroll.scrollEnabled = YES;
    scroll.directionalLockEnabled = YES;

    for(int i=0;i<4;i++)
    {
        guideView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*i,0, 320, self.view.frame.size.height)];
        guideView.tag = i+1;
        //if(i==0)
        NSString *imgName = [NSString stringWithFormat:@"bg_intro%d", i+1];
        UIImage  *img= GET_IMAGE_FROM_BUNDLE_PATH(ADAPT_IMAGE_NAME(imgName) ,@"UserGuideImage");
        guideView.image = img;
        guideView.userInteractionEnabled=YES;
        [scroll addSubview:guideView];
        scroll.contentSize = CGSizeMake(SCREEN_WIDTH*(i+1), 0);
        if (guideView.tag==4)
        {
            UITapGestureRecognizer *tapGR=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchDown)];
            [guideView addGestureRecognizer:tapGR];
        }
    }
        
    [self.view addSubview:scroll];
    pageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT-50 ,SCREEN_WIDTH, 21)];
    pageControl.backgroundColor=[UIColor clearColor];
    pageControl.numberOfPages=4;
    pageControl.currentPage=0;
    [self.view addSubview:pageControl];

}
/**
 *  pageControl
 *
 *  @param scrollView scrollView
 */
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat pageWidth = self.view.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = page;
    
}
/**
 *  手势方法
 */
-(void)touchDown
{
    if ([self.delegate respondsToSelector:@selector(removeGuideView)])
    {
        [self.delegate removeGuideView];
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

然后在调用的地方:

#pragma mark - 显示引导页

  if (![[NSUserDefaults standardUserDefaults] boolForKey:@"YES"])
    {
       [self showGuideView];
    }
else

{

//TODO

}

-(void)showGuideView
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"YES"];
    UseGuideViewController *guideView = [[UseGuideViewController alloc]init];
    guideView.delegate = self;
}

#pragma mark --引导图代理
-(void)removeGuideView
{

//TODO

}

iOS引导页,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。