정상적으로 셀이있는 UICollectionView
이 있습니다.UICollectionView isUserInteractionEnabled가 셀 상호 작용을 차단합니다.
각 셀에는 그 자체가 UICollectionViewController
입니다. 내가 셀을 탭하면
, 나는 그것이 윈도우 화면에 맞게 확장,하지만 난 여기에 몇 가지 문제가 발생했습니다 :
내가 확장 된 세포 내에서 스크롤하면 전체 화면 스크롤;
superview 컬렉션보기 탭 및 스크롤을 차단하기 위해 노력하고 있습니다.
는 원하는 프레임에 맞게 선택한 셀을 확장 한 후,이를 위해, 나는collectionView.isScrollEnabled = false
및
collectionView.isUserInteractionEnabled = false
설정할 수 있지만이와 나는 또 다른 문제를 건너 왔어요 : 확장 된 셀은 어떤 터치와 상호 작용하지 않습니다.
어떻게하면됩니까? 셀을 확장하고 스크롤보기 스크롤을 차단하고 스크롤보기 상호 작용을 차단하지만 셀 상호 작용을 사용하도록 설정하십시오 (스크롤 탭 등)?
다음은 코드의 일부입니다 :
홈페이지 피드 컨트롤러
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let cell = collectionView.cellForItem(at: indexPath) as? FeedCell else { return }
let theAttributes:UICollectionViewLayoutAttributes! = collectionView.layoutAttributesForItem(at: indexPath)
let cellFrameInSuperview:CGRect = collectionView.convert(theAttributes.frame, to: collectionView)
cell.superview?.bringSubview(toFront: cell)
cell.backupFrame = cellFrameInSuperview
let newFrame = CGRect(x: 0, y: collectionView.contentOffset.y, width: view.frame.width, height: view.frame.height)
UIView.animate(withDuration: 0.2, animations: {
cell.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
}) { (_) in
UIView.animate(withDuration: 0.1, animations: {
cell.transform = CGAffineTransform(scaleX: 1, y: 1)
}, completion: { (_) in
UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.7, options: .curveEaseInOut, animations: {
cell.frame = newFrame
},completion: {(_) in
cell.presentDismissButton()
self.collectionView.isScrollEnabled = false
self.collectionView.isUserInteractionEnabled = false
})
})
}
}
확장 셀 나는 수퍼 상호 작용을 설정할 수 있습니다 기각 특성에서 버튼 속성
@objc func dismiss() {
UIView.animate(withDuration: 0.8, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1, options: .allowAnimatedContent, animations: {
self.frame = self.backupFrame!
self.sendSubview(toBack: self)
self.dismissButton.alpha = 0
},completion: nil)
}
기각 다시 활성화되었지만 확장 된 프레임을 사용하면 그것으로 ct.
기본 피드 collectionView 상호 작용을 사용 중지하지 않으면 한 가지 문제가 있습니다. 확장 된 셀의 아무 곳이나 누르면 확장 된 셀 뒤에있는 다른 셀 (확장 된 셀 뒤에있는 터치 이벤트를 받게됩니다)이 확장됩니다. didSelectItem(:_)
감사합니다.
다음과 같이 셀 뒤에 하위보기를 추가 할 수 있습니다. https://stackoverflow.com/a/5404921/8374624 –
@JakobMygind 네, 좋은 접근 방법입니다. 방금 기억했던 것은'hasCellExpanded = false'와 같은 것을 추가하는 것이 었습니다. 그리고 셀이 확장되었을 때 그것을 true로 설정하고,'hasCellExpanded == true' 만 리턴하면'didSelectItemAtIndexPath (_ :)'에 리턴했습니다. –