CCView
您想在 Podfile 中添加类似于以下内容的 pod 'CCView', '~> 1.1.3'
target 'MyApp' do
pod 'CCView', '~> 1.1.3'
end
然后在您的终端中运行 pod install,或从 CocoaPods.app 运行。
如何使用?
首先,导入您想使用 CCView 的类
import CCView
使用 XIB 创建 UICollectionViewController 和 UICollectionViewCell 类,并将类类型分别更改为 CCCollectionViewController 和 CCCollectonViewCell
对于 UICollectionViewController:-
class CollectionViewController: CCCollectionViewController,UICollectionViewDelegateFlowLayout {
.
.
.
.
}
对于 UICollectionViewCell:-
class CollectionViewCell: CCCollectionViewCell {
.
.
.
.
}
在 UICollectionViewController 中需要修改
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell:CollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CollectionViewCell
.
.
self.toggleCell(cellInstance: cell, indexPath: indexPath, for: 0.5) //0.5 is the duration for animaiton
.
.
return cell
}
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
.
.
.
self.expandCell(collectionView, at: indexPath, for: 0.7) //0.7 is the durartion for animation
}
或调用 self.expandCell(collectionView, at: indexPath, for: duration) 在单元格的展开动作中
对于 UICollectionViewCell:-
使用 XIB 创建一个 CollectionViewCell 类,并根据所需的结果创建与演示类似的布局,并在您的 CCCollecitonViewCell 类中添加以下代码
override���� func defaultLayoutForClosedCell(lowerDetailsView:UIView,lowerView:UIView) -> Void {
super.defaultLayoutForClosedCell(lowerDetailsView:lowerDetailsView,lowerView:lowerView)
self.lowerDetailsView.isHidden = true
self.lowerView.transform = CGAffineTransform(scaleX: 0.3, y: 0.3)
self.layoutIfNeeded()
}
override func animateCloseCell(lowerDetailsView:UIView,lowerView:UIView,animationDuration:Double) -> Void {
super.animateCloseCell(lowerDetailsView:lowerDetailsView,lowerView:lowerView,animationDuration:animationDuration)
UIView.animate(withDuration: animationDuration) {
self.lowerDetailsView.isHidden = true
self.lowerView.transform = CGAffineTransform(scaleX: 0.3,y: 0.3)
self.layoutIfNeeded()
}
}
override func animateCellOpen(lowerDetailsView:UIView,lowerView:UIView,animationDuration:Double) -> Void {
super.animateCellOpen(lowerDetailsView:lowerDetailsView,lowerView:lowerView,animationDuration:animationDuration)
UIView.animate(withDuration: animationDuration) {
self.lowerView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
self.lowerDetailsView.isHidden = false
self.layoutIfNeeded()
}
}
演示应用程序 gif
演示应用程序链接
![演示示例][https://github.com/harshsrivastavaglobussoft/CCViewDemo]
需求:
- XCode 9.4+
- Swift 4
作者
Harsh Srivastava