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

首頁 > 系統 > iOS > 正文

iOS 輪播視圖的實現方式 和 RunLoopMode 的注意

2019-11-09 15:21:19
字體:
來源:轉載
供稿:網友

通過 CollectionView 實現

需要哪些組件

collectionViewpageControlNSTimer

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);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 广河县| 治多县| 扶绥县| 铁力市| 邮箱| 二手房| 全南县| 武陟县| 商南县| 韶山市| 北川| 凤翔县| 沧州市| 洞口县| 伊川县| 图木舒克市| 巫溪县| 海原县| 济南市| 九江市| 永城市| 南漳县| 隆德县| 苍山县| 上林县| 巴林左旗| 昆明市| 林西县| 清丰县| 巴里| 马关县| 杭锦旗| 郁南县| 和平县| 宿迁市| 景宁| 海原县| 如皋市| 牡丹江市| 正宁县| 韶山市|