iOS 轮播视图的实现方式 和 RunLoopMode 的注意
来源:互联网 发布:centos制作u盘启动 编辑:程序博客网 时间:2024/06/04 23:33
通过 CollectionView 实现
需要哪些组件
- collectionView
- pageControl
- NSTimer
collectionView
- cell 图片的载体
- contentsOffset 内容的偏移量
- indexpath 当前滚动的cell的indexPath
如何轮播?
NSInteger curIndex = (self.collectionView.contentOffset.x + self.layout.itemSize.width * 0.5) / self.layout.itemSize.width; //计算将要滚到的Index,如果是将要滚到第一个,就把toIndex = 0; NSInteger toIndex = curIndex + 1; if (toIndex == self.totalPageCount) { toIndex = 0; [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
pageControl
//需要在scrollViewDidScroll中计算 currentPage-(void)scrollViewDidScroll:(UIScrollView *)scrollView { int itemIndex = (scrollView.contentOffset.x + self.collectionView.xjy_width * 0.5) / self.collectionView.xjy_width; itemIndex = itemIndex % self.imageUrls.count; _pageControl.currentPage = itemIndex;}
NSTimer
- RunLoopMode kCFRunLoopCommonModes(RunLoop的问题看我的Runloop博文)
- @selector() 要执行自动轮播的方法
if (self.timer) { CFRunLoopTimerInvalidate(self.timer); CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), self.timer, kCFRunLoopCommonModes); } __weak __typeof(self) weakSelf = self; CFRunLoopTimerRef timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + _timeInterval, _timeInterval, 0, 0, ^(CFRunLoopTimerRef timer) { [weakSelf autoScroll]; }); self.timer = timer; CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
1 0
- iOS 轮播视图的实现方式 和 RunLoopMode 的注意
- iOS 广告轮播注意点和定时器的三种实现方法
- 多播的实现和需要注意的问题
- 多播的实现和需要注意的问题
- 【miscellaneous】多播的实现和需要注意的问题
- iOS--轮播视图
- Swift实现"视差效果"的视图轮播
- iOS开发之collectionView实现无限轮播视图
- IOS学习(八)滚动视图实现轮播
- iOS广告轮播视图
- viewpager实现无限轮播的两种方式总结
- 一种实现ViewPager图片轮播的方式
- 图片轮播的两种实现方式(一)
- IOS开发实现 UIScrollView 的循环轮播功能
- iOS实现图片轮播的简易步骤
- iOS -- 用collectionView实现图片的无限轮播
- iOS 第12课 图片轮播的实现
- IOS边下边播方法的实现
- EventBus的基本使用
- 小鑫の日常系列故事(十)——排名次 (sdut oj)
- 快速上手Vue(适合懂基础html、css和js的人)
- 面试-webservice
- 自己刚学时候的链表整理一下,方便以后翻阅
- iOS 轮播视图的实现方式 和 RunLoopMode 的注意
- Android布局
- 求二叉树的深度
- Performing summary statistics and plots —— Python Data Science Cookbook
- 深入理解JVM(二)——揭开HotSpot对象创建的奥秘
- UOJ 73 [WC2015]未来程序
- Linux下" >/dev/null 2>&1 "相关知识说明
- Android获取联系人
- 基于代数距离的椭圆拟合