国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS 輪播視圖的實現(xiàn)方式 和 RunLoopMode 的注意

2019-11-09 16:36:59
字體:
供稿:網(wǎng)友

通過 CollectionView 實現(xiàn)

需要哪些組件

collectionViewpageControlNSTimer

collectionView

cell 圖片的載體contentsOffset 內(nèi)容的偏移量indexpath 當(dāng)前滾動的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() 要執(zhí)行自動輪播的方法 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);
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 卢氏县| 安庆市| 天津市| 新郑市| 鹰潭市| 郁南县| 崇州市| 洪泽县| 亚东县| 锡林郭勒盟| 弋阳县| 大名县| 新蔡县| 平利县| 淳安县| 霍州市| 综艺| 洛川县| 敦化市| 福海县| 什邡市| 宣武区| 萝北县| 水城县| 台中市| 吐鲁番市| 鞍山市| 天峻县| 石柱| 定陶县| 梓潼县| 保亭| 沁源县| 临泽县| 都江堰市| 讷河市| 四川省| 安宁市| 方山县| 大城县| 大兴区|