标签: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
}
标签:http color os io 文件 for ar cti
原文地址:http://my.oschina.net/u/1025290/blog/300009