2016-12-14 74 views
2

我正在使用NVActivityIndicatorView加载动画。 我有这些功能来添加和删除活动指标。隐藏标题,而收集视图正在加载

func addActivityIndicator() {} 
func startActivityIndicatorView() {} 
func stopActivityIndicatorView() {} 

我有我实现

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 
    let headerView = ... 
    return headerView 
} 

我的问题是报头是可见的,而的CollectionView加载一个头。我想隐藏它,而collectionView正在加载。

回答

0

而指示灯动画,所以你应该让集合视图你可能会执行一些异步操作知道该操作是通过调用reloadData所以它会重新布局其UI元素,包括头通过viewForSupplementaryElementOfKind完成:

首先,你需要的是从collectionView:layout:referenceSizeForHeaderInSection返回CGSize.zero如果指示灯亮屏幕,这样的标题不会填充:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { 
    if indicatorView.isAnimating { 
    return CGSize.zero 
    } else { 
    return CGSize(width: collectionView.frame.width, height: 50) 
    } 
} 

那么无论你隐藏活动的指标(可能在共异步操作)的mpletion块,你应该叫collectionView.reloadData所以viewForSupplementaryElementOfKind将会再次调用:

// operation is done, refreshing the content.. 
self.stopActivityIndicatorView() 
self.collectionView.reloadData() 
... 
+0

viewForSupplementaryElementOfKind不接受零的回报。 –

+0

对不起,我完全错过了,但没想到。如果指标是动画,则需要在相应的委托方法中返回“CGSize.zero”作为标题高度。将'viewForSupplementaryElementOfKind'保持原样并使用相同的想法更新['referenceSizeForHeaderInSection'](https://developer.apple.com/reference/uikit/uicollectionviewdelegateflowlayout/1617702-collectionview?language=objc)。 – ozgur

+0

eyvallahÖzgür:)谢谢。请更新您的答案,我会标记它... –