我們經(jīng)常在開發(fā)中遇到頁面切換,看需求,用collectionView還是很方便,下面的代碼可以實現(xiàn) -- > 在新特性頁面,最后一個頁面上會顯示button,點擊button會跳轉(zhuǎn)App的主頁面,一定要避免cell的復(fù)用問題哦~~~
//即將顯示的時候所有按鈕隱藏
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
let cell = cell as!WWNewfeatureCell
cell.startButton.hidden = true
}
//完全顯示一個cell調(diào)用
func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
//上一頁的索引
print(indexPath.item)
//當(dāng)前的可見cell的indexPath
let index = collectionView.indexPathsForVisibleItems().last!
print("\(index.item )")
//當(dāng)前cell
let cell = collectionView.cellForItemAtIndexPath(index) as!WWNewfeatureCell
if index.item == (4 - 1){
//讓cell執(zhí)行按鈕的動畫
cell.startButtonAnim()
}
}