国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 孙吴县| 普格县| 来凤县| 太保市| 呼伦贝尔市| 启东市| 彩票| 天台县| 江川县| 泾阳县| 肇东市| 东乌珠穆沁旗| 施甸县| 宝应县| 和顺县| 德化县| 方山县| 临高县| 视频| 弥勒县| 潢川县| 磐安县| 彭阳县| 福海县| 县级市| 宝丰县| 延边| 涿州市| 马公市| 吉首市| 大荔县| 始兴县| 丽水市| 巴林右旗| 宝清县| 永德县| 龙陵县| 龙陵县| 大渡口区| 绥化市| 离岛区|