UICollectionView로 만든 메뉴에 애니메이션을 적용하려고합니다. 아래에서 볼 수있는 2 개의 콜렉션 뷰가 있습니다.UICollectionViewCell 애니메이션이있는 프로토콜
그리고 아래로 스크롤 할 때 상단 표시 줄에 애니메이션을 시도하고있다. 애니메이션이 완료되면 "포켓몬"레이블이 흰색으로 표시되고 포켓몬 이미지는 숨겨지고 배경은 파란색으로 표시됩니다. 나는 세포에 도달하기 위해 프로토콜을 사용합니다. 이것은 내 ViewController 클래스입니다.
protocol TopCategoriesDelegator{
func openTopBar()
func closeTopBar()}
그리고 이것은
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)
}
}
상하 스크롤 감지 cellForRowAt
함수이고; 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()
}
}
}
는 그리고이
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 클래스입니다. 그러나 첫 번째 요소 만 사라지고 다른 요소는 이와 같이 유지됩니다.
어떻게 다른 세포의 이미지를 숨길 수 있습니까?
감사합니다.
위치를 'self.categoryImage'의 값을 설정하는에서? –
스토리 보드에 설치했는데, 지금 디자인 부분에 붙어 있습니다. – Azat
그리고 collectionView의 최상위 포켓몬 이미지입니까? –