标签:
#import "RootViewController.h" #import "SecondViewController.h" #define kScreenWidth [UIScreen mainScreen].bounds.size.width #define kScreenHeight [UIScreen mainScreen].bounds.size.height #define kImageCount 6 #define kImageName @"v6_guide_" @interface RootViewController ()<UIScrollViewDelegate> @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self layoutSubview]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //布局视图 - (void)layoutSubview{ [self layoutScrollView]; [self layoutPageControl]; } //布局UIScrollView - (void)layoutScrollView{ //1.创建对象 UIScrollView *scrollView =[[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds]; //2.配置属性 scrollView.contentSize = CGSizeMake(kScreenWidth * kImageCount, kScreenHeight); //关闭水平指示器,就是水平滚动条 scrollView.showsHorizontalScrollIndicator = NO; //设置scrollView 能否整屏滑动 scrollView.pagingEnabled = YES; //设置代理 scrollView.delegate = self;// 此时设置代理的目的,在协议的减速方法中,让scrollView与pageControl中建立联系 scrollView.tag = 200; //3.添加到父视图 [self.view addSubview:scrollView]; //4.释放 [scrollView release]; //创建UIImageView for (int i = 0; i < kImageCount; i++) { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth * i, 0, kScreenWidth, kScreenHeight)]; imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d", kImageName, i + 1]]; [scrollView addSubview:imageView]; [imageView release]; //判断是否是最后一张图片 if (kImageCount - 1 == i) { //如果是最后一个imageView添加轻拍手势,为了进入该程序的主界面 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; //添加到视图 [imageView addGestureRecognizer:tapGesture]; //释放 [tapGesture release]; //打开imageView的用户交互 imageView.userInteractionEnabled = YES; } } } //布局UIPageControl - (void)layoutPageControl{ UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(20, kScreenHeight - 30 * 2, kScreenWidth - 20 * 2, 30)]; pageControl.numberOfPages = kImageCount; pageControl.currentPageIndicatorTintColor = [UIColor blackColor]; pageControl.tag = 300; pageControl.pageIndicatorTintColor = [UIColor grayColor]; //添加响应事件 [pageControl addTarget:self action:@selector(handlePageControl:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:pageControl]; [pageControl release]; } - (void)handlePageControl:(UIPageControl *)pageControl { //1.获取到scrollView UIScrollView *scrollVW = (UIScrollView *)[self.view viewWithTag:200]; //2.修改scrollView偏移量 [scrollVW setContentOffset:CGPointMake(kScreenWidth *pageControl.currentPage , 0) animated:YES]; } #pragma mark - UIScrollViewDelegate - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { //1.获取pageControl UIPageControl *pageCT = (UIPageControl *)[self.view viewWithTag:300]; //2.设置pageControl索引,当前的点 目的让点随着图而动 pageCT.currentPage = scrollView.contentOffset.x / kScreenWidth; } #pragma 轻拍手势 - (void)handleTapGesture:(UITapGestureRecognizer *)tap { //进入程序界面 SecondViewController *secondViewController = [[SecondViewController alloc] init]; //将secondVC指定为window的根视图 [UIApplication sharedApplication].keyWindow.rootViewController = secondViewController; //释放 [secondViewController release]; } @end
判断是否第一次登陆
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. //用户索引项,存储用户信息,程序是否是第一次启动,以及保存用户密码等. NSUserDefaults *userDefalts = [NSUserDefaults standardUserDefaults]; if (![userDefalts boolForKey:@"FirstLanch"]) { //把标志符存入本地,下一次判断,滤过分支 [userDefalts setBool:YES forKey:@"FirstLanch"]; //立即同步 [userDefalts synchronize]; RootViewController *rootView = [[RootViewController alloc] init]; self.window.rootViewController = rootView; [rootView release]; }else { SecondViewController *secondVC = [[SecondViewController alloc] init]; self.window.rootViewController = secondVC; [secondVC release]; } self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; }
//引导界面结束后的视图
@implementation SecondViewController - (void)viewDidLoad { [super viewDidLoad]; UIImageView *imgeView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 50, [UIScreen mainScreen].bounds.size.width - 40 * 2, [UIScreen mainScreen].bounds.size.height - 50 * 2)]; imgeView.image = [UIImage imageNamed:@"1.jpg"]; [self.view addSubview:imgeView]; [imgeView release]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
iOS中ScrollView(滚屏,引导界面,和判段是否是第一次登陆)
标签:
原文地址:http://www.cnblogs.com/wohaoxue/p/4764660.html