UI-ScrollView的使用
2015-08-04 10:43
411 查看
//相对位置,学会使用-scrollView.contentSize = CGSizeMake(320*3,160); #import "ViewController.h" @interface ViewController () { UIScrollView *_scrollView1; UIScrollView *_scrollView2; UIScrollView *_scrollView3; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _scrollView1 = [[UIScrollView alloc]init]; _scrollView1.frame = CGRectMake(0, 0, 320, 160); _scrollView1.bounces = NO; _scrollView1.pagingEnabled = YES; _scrollView1.delegate = self; _scrollView1.tag = 2; _scrollView1.contentSize = CGSizeMake(320*3, 160); [self.view addSubview:_scrollView1]; for (int i = 0; i < 3; i++) { UILabel * label = [[UILabel alloc]init]; label.frame = CGRectMake(320*i, 0, 320, 160); label.backgroundColor = [UIColor redColor]; label.text = [NSString stringWithFormat:@"%d 只鸡",i+1]; label.font = [UIFont boldSystemFontOfSize:30]; label.textAlignment = NSTextAlignmentCenter; [_scrollView1 addSubview:label]; } _scrollView2 = [[UIScrollView alloc]init]; _scrollView2.frame = CGRectMake(0, 160, 320, 160); _scrollView2.bounces = NO; _scrollView2.pagingEnabled = YES; _scrollView2.contentSize = CGSizeMake(320*3, 160); _scrollView2.delegate = self; _scrollView2.tag = 4; [self.view addSubview:_scrollView2]; for (int i =0; i<3; i++) { UILabel * label = [[UILabel alloc]init]; label.frame = CGRectMake(320*i, 0, 320, 160);//这里是相对于scrollView设定的 label.backgroundColor = [UIColor blueColor]; label.textAlignment = NSTextAlignmentCenter; label.text = [NSString stringWithFormat:@"%d只羊",i+1]; label.font = [UIFont boldSystemFontOfSize:30]; [_scrollView2 addSubview:label]; } _scrollView3 = [[UIScrollView alloc]init]; _scrollView3.frame = CGRectMake(0, 320, 320, 160); _scrollView3.bounces = NO; _scrollView3.delegate = self; _scrollView3.pagingEnabled = YES; _scrollView3.contentSize = CGSizeMake(320*18, 160); [self.view addSubview:_scrollView3]; for (int i = 0; i < 18; i++) { UILabel *label = [[UILabel alloc]init]; label.frame = CGRectMake(320*i, 0, 320, 160); label.textAlignment = NSTextAlignmentCenter; label.backgroundColor = [UIColor cyanColor]; label.text = [NSString stringWithFormat:@"%d只腿",i+1]; label.font = [UIFont boldSystemFontOfSize:30]; [_scrollView3 addSubview:label]; } // Do any additional setup after loading the view, typically from a nib. } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { int sum = (_scrollView1.contentOffset.x/320+1)*_scrollView1.tag + (_scrollView2.contentOffset.x/320+1)*_scrollView2.tag; [_scrollView3 setContentOffset:CGPointMake((sum-1)*320,0)] ; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- String、StringBuffer和StringBuilder
- BluetoothAdapter.LeScanCallback 参考文档
- iOS多线程之NSOperation,NSOperationQueue
- PHP中 include,include_once,require,require_once的区别详解
- poj 3907 Build Your Home(任意多边形面积)
- ${pageContext.request.contextPath} JSP取得绝对路径
- Storyboard里面的几种Segue区别:push,modal,popover,replace和custom
- Android GUI之View测量
- Xamarin.Forms之FluentValidation(Model验证)
- easyui tabs update 强制刷新页面
- Android GUI之View测量
- NGUI Sprite Type类型详解
- js中获取 <%=request.getContextPath()%>
- liquibase安装
- HDU 4675 GCD of Sequence
- 解决ntp的错误 no server suitable for synchronization found
- iOS AudioQueue机制的延迟问题探究
- poj 2478 Farey Sequence(欧拉函数)
- [leetcode-63]Unique Paths II(c)
- 在转换为 UTC 时大于 DateTime.MaxValue 或小于 DateTime.MinValue 的 DateTime 值无法系列化为 JSON