UIScrollView循环滚动
来源:互联网 发布:idc 手机出货量数据 编辑:程序博客网 时间:2024/05/16 08:04
循环滚动原理很简单,注释中可以看到
//// ViewController.swift//import UIKitclass ViewController: UIViewController,UIScrollViewDelegate { let _widthSV:CGFloat = UIScreen.mainScreen().bounds.size.width - 20 let _heightSV:CGFloat = 200 let _scrollView:UIScrollView = UIScrollView() //图片循环滚动原理 //两边各加一张图片,按照 1 2 3 4 5 6 顺序对应下面六张图片 //当滚动至6时触发函数 scrollViewDidScroll 中的条件语句 s2 让画面在感觉不到的情况下跳转至2 //当滚动至1时触发函数 scrollViewDidScroll 中的条件语句 s1 让画面在感觉不到的情况下跳转至5 let picNames:NSArray = NSArray(array: ["pic4", "pic1", "pic2", "pic3", "pic4", "pic1"]) override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.view.addSubview(_scrollView) _scrollView.frame = CGRectMake(10, 50, _widthSV, _heightSV) for var i = 0; i < picNames.count; i++ { let nameStr:NSString = picNames[i] as! NSString let imageView:UIImageView = UIImageView(frame: CGRectMake(CGFloat(i) * _widthSV, 0, _widthSV, _heightSV)) let imageFileStr:NSString = NSBundle.mainBundle().pathForResource(nameStr as String, ofType: "jpg")! imageView.image = UIImage(contentsOfFile: imageFileStr as String) _scrollView.addSubview(imageView) } _scrollView.contentSize = CGSizeMake(CGFloat(picNames.count) * _widthSV, 0) _scrollView.pagingEnabled = true _scrollView.contentInset = UIEdgeInsetsZero _scrollView.setContentOffset(CGPointMake(_widthSV, 0), animated: false) _scrollView.delegate = self _scrollView.showsHorizontalScrollIndicator = false //不显示滚动条 } func scrollViewDidScroll(scrollView: UIScrollView) { let point = scrollView.contentOffset if Int(point.x) == 0 { //s1 scrollView.setContentOffset(CGPointMake(_widthSV * CGFloat(picNames.count - 2), 0), animated: false) }else if Int(point.x) == Int(_widthSV * CGFloat(picNames.count - 2 + 1)) { // s2 scrollView.setContentOffset(CGPointMake(_widthSV, 0), animated: false) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }}
0 0
- 循环滚动一个UIScrollView
- uiscrollview 无缝循环滚动
- uiscrollview 无缝循环滚动
- 实现UISCrollView循环滚动
- UIScrollView自动循环滚动
- UIscrollView图片滚动循环
- UIScrollView循环滚动
- UIScrollView(图片循环滚动)
- uiscrollview 无缝循环滚动
- UIScrollView的循环滚动
- 实现UIScrollView循环滚动
- UIScrollView (API+循环滚动)
- UIScrollView实现循环滚动
- UIScrollView(循环滚动图片)
- UIScrollView循环滚动
- 实现UIScrollView循环滚动
- UIScrollView代码实现循环滚动
- UIScrollView代码实现循环滚动
- 对一个多态例题学习的一些思考
- 常规功能和模块自定义系统 (cfcmms)—033更改至现在为止的版本下载
- node.js初识
- Swift中文教程(一)基础数据类型
- MFC学习(23)MFC 文件操作详解
- UIScrollView循环滚动
- 跟我一起写Makefile 读书笔记
- java发邮件(1)
- 手机APP模式 之 Hybrid App(混合模式移动应用)
- Android 的 dex2jar 和 jd-gui 反编译 apk 源代码
- v$archived_log视图中,有关时间的几列的含义
- Python语言基础
- android ListView 动态切换Item布局
- ♥CodeForces 609B-B. The Best Gift【组合数学】