2017-01-05 160 views
0

我創建了這個界面,collectionView爲製表符和pageViewController滑動頁面,我得到頁面的索引時,我滑動但無法更改collectionViewTab如何更改它?有人告訴我,如何更新collectionViewTab底部指標?Swift:滑動UICollectionView和UIPageViewController

func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { 

    } 

在此我得到正確的頁面索引:

enter image description here

回答

2

你在正確的道路上。 當您在UIPageViewController上滑動時,您將獲得當前頁面索引。您應該將該索引保存到類變量中,並在cellForItemAtIndexPath中使用它來確定當前顯示的選項卡索引是否匹配UIPageViewController。所以,這樣的事情應該工作:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("reuseIdentifier", forIndexPath: indexPath) 

     if indexPath.item == classIndexVariable { 
     bottomIndicator.isHidden = false // show indicator at current position 
     }else{ 
     bottomIndicator.isHidden = true // hide indicator from all only shows in matched condition 
     } 

     return cell 
    } 

解釋道: 在cellForItemAtIndexPath你要比較你UIPageViewController didFinishAnimating功能保存指數當前單元格的索引。如果它匹配你有活動標籤 - 顯示底部指標。如果索引不匹配,則您的選項卡未激活,因此不顯示底部指示符。

正如我所說,請記住,這只是一個snipper。不知道你的代碼是什麼樣的,我猜你正在做這樣的事情。

+0

我做了正確的U說U給了正確的解決方案它爲我工作謝謝 – User

相關問題