iOS引導頁

來源:互聯網
上載者:User

標籤:http   color   os   io   檔案   for   ar   cti   

我這裡是的引導頁是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

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.