2017-01-05 88 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

相关问题