iOS中ScrollView(滚屏,引导界面,和判段是否是第一次登陆)
2015-08-27 21:17
501 查看
#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-点餐系统
- iOS判断设备-userInterfaceIdiom
- iOS-汤姆猫项目总结
- ios tableView 的header for section无法加载的问题
- 苹果开发文档 User Experience Starting Point for iOS
- iOS Provisioning Profile(Certificate)与Code Signing详解
- iOS 万能跳转界面方法
- ios即时通讯客户端开发之-mac上搭建openfire服务器
- ios-QQ界面(利用新浪微博方法实现,消除新浪微博重复计算的缺点)
- iOS:NSDate的主要几种时间形式
- 美食屋-ios 项目
- ios- 自定义cell总结
- IOS学习之单例的实现
- iOS百度地图在线建议api做搜索区域推荐
- 基于LBS平台的iOS开发
- iOS安全攻防越狱检测的攻与防
- IOS7 点击空白处隐藏键盘的几种方法
- iOS开发系列--地图与定位
- Safari调试iOS中的js
- VCTransitionsLibrary –自定义iOS交互式转场动画的库