UIPageView和UIScrollView的结合使用
来源:互联网 发布:大闹天宫魅羽进阶数据 编辑:程序博客网 时间:2024/05/07 21:57
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor];// 用户偏好设置 存储在本地 比如程序是否第一次加载// NSUserDefaults *user = [NSUserDefaults standardUserDefaults];// if (![user boolForKey:@"aa"]) { [self setupFirstLanchView];// [user setBool:YES forKey:@"aa"];// //立即同步// [user synchronize];// } /** * UIPageControl 表示所有的页数,表示当前正处于第几页,点击切换页数 **/ }//创建程序第一次加载要显示的视图-(void)setupFirstLanchView{ [self setupScrollView]; [self setUpPageControl];}-(void)setupScrollView{ UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds]; scrollView.pagingEnabled = YES; scrollView.showsVerticalScrollIndicator = NO; scrollView.showsHorizontalScrollIndicator = NO; scrollView.bounces = NO; scrollView.delegate = self; scrollView.contentSize = CGSizeMake(320 * 6, [UIScreen mainScreen].bounds.size.height) ; scrollView.tag = 100; [self.view addSubview:scrollView]; [scrollView release]; for (int i = 0 ; i < 6; i ++) { UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(320 * i, 0, 320, [UIScreen mainScreen].bounds.size.height)]; imageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"v6_guide_%d",i + 1] ofType:@"png"]]; [scrollView addSubview:imageView]; [imageView release]; }}-(void)setUpPageControl{ UIPageControl *pagecontrol = [[UIPageControl alloc]initWithFrame:CGRectMake(10, [UIScreen mainScreen].bounds.size.height - 40, 300, 20)]; //页数 pagecontrol.tag = 101; pagecontrol.numberOfPages = 6;// //未选中圆点颜色 pagecontrol.pageIndicatorTintColor = [UIColor greenColor];// //设置选中点的颜色 pagecontrol.currentPageIndicatorTintColor = [UIColor redColor]; //设置当前显示页 从零开始 pagecontrol.currentPage = 0; // 添加响应事件 [pagecontrol addTarget:self action:@selector(handlePageControl:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:pagecontrol]; [pagecontrol release];}-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ // 当结束拖拽时触发 NSLog(@"%s",__FUNCTION__); UIPageControl *page = (UIPageControl *) [self.view viewWithTag:101]; page.currentPage = scrollView.contentOffset.x/320; NSLog(@"%f",scrollView.contentOffset.x); NSLog(@"%ld",(long)page.currentPage);}-(void)handlePageControl:(UIPageControl *)pageControl{ NSLog(@"%ld",(long)pageControl.currentPage);// 切换pageControl对应切换scrollView UIScrollView *scrollView = (UIScrollView *)[self.view viewWithTag:100]; [scrollView setContentOffset:CGPointMake(320*pageControl.currentPage, 0) animated:YES]; NSLog(@"%f",scrollView.contentOffset.x);}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
0 0
- UIPageView和UIScrollView的结合使用
- UIScrollView和UIPageView基本用法
- UI UIScrollView和UIPageControl的结合使用
- UIScrollView和自定义PageControl的结合使用
- UIScrollerView和UIPageView联合使用
- UIPageController和UIScrollView结合使用
- Quick中UIPageView的使用
- iOS UIPageView与UIScrollView
- UIScrollView,UIPageControl的结合使用
- UIPageControl与UIScrollView的结合使用
- UIScrollView + AutoLayout结合使用
- UIScrollView和UIPageControl结合
- UIScrollView与UIPageControl结合使用
- UIScrollView 和自动布局结合
- UIScrollView的分页和使用
- UIPageView
- UIscrollView的用法和代理的使用
- UIScrollView结合UIPageControl+NSTimer使用简介
- POJ 2976 Dropping tests & 分数规划讲解
- Tcl/Tk: string详解
- Codeforces Round #267 (Div. 2) C. George and Job(DP)
- leetcode - Pow(x, n)
- 花生壳内网IP如何实现搭建网站发布到外网
- UIPageView和UIScrollView的结合使用
- Linux主机shell脚本一步备份笔记至手机,并实现轮转
- JavaIO详解
- JAVA深入学习之Apache开源项目
- Linux中断机制
- 置换群
- Codeforces Round #267 (Div. 2) B. Fedor and New Game(位运算)
- leetcode - Reverse Integer
- Hadoop 之 数据去重(星星笔记)