UICollectionViewで作成したメニューをアニメーション表示しようとしています。私はあなたが下記で見ることができる2つのコレクションビューをもう1つ持っています。UICollectionViewCellアニメーションプロトコル付き
そして、私はスクロールダウン時に上部のバーをアニメーション化しようとしています。アニメーションが完成すると、「ポケモン」のラベルは白くなり、ポケモンのイメージは隠され、背景は青色になります。私はプロトコルを使って細胞に到達します。これは私のViewControllerクラスです。
protocol TopCategoriesDelegator{
func openTopBar()
func closeTopBar()}
そして、これはcellForRowAt機能
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.collectionView{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "topCategory", for: indexPath) as! TopCategoriesCell
cell.viewController = self
return cell
}else if collectionView == subCategoriesCollectionView{
return collectionView.dequeueReusableCell(withReuseIdentifier: "subCategories", for: indexPath)
}else{
return collectionView.dequeueReusableCell(withReuseIdentifier: "productCell", for: indexPath)
}
}
そして、スクロールダウンの検出のためにあります。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
// print(scrollView.contentOffset.y)
if scrollView.contentOffset.y > 160 {
if self.cellDelegate != nil{
self.cellDelegate.closeTopBar() // func in main vc for background color and size
closeAnimation()
}
}else{
if self.cellDelegate != nil{
self.cellDelegate.openTopBar() // func in main vc for background color and size
openAnimation()
}
}
}
そして、これがTopCategoriesCellクラス
override func layoutSubviews() {
if let vc = viewController as? ProductsVC{
vc.cellDelegate = self
}
}
func closeTopBar() {
UIView.animate(withDuration: 0.3) {
self.categoryImage.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
self.categoryImage.isHidden = true
}
}
func openTopBar(){
UIView.transition(with: categoryImage, duration: 0.3, options: .curveEaseIn, animations: {
self.categoryImage.isHidden = false
self.categoryName.textColor = UIColor().rgb(red: 37.0, green: 110.0, blue: 140.0)
}, completion: nil)
}
は実際にすべてが正常に動作しています。しかし、最初の要素だけが消えて、他の要素はこのようにそこにとどまります。
どのように私は他の細胞の画像を非表示にできますか?
ありがとうございます。
:
そして
TopCategoriesCell
で? –私はストーリーボードにセットしました。 – Azat
そしてcollectionViewのトップバーのポケモンの画像は? –