UIExpandableCVCellKit 1.04

UIExpandableCVCellKit 1.04

Yung Dai 维护。



  • 作者
  • Yung Dai

UIExpandableCVCellKit

一个框架,用于在选择 UICollectionViewCell 时向单元格添加类似 Apple Appstore 的动画,使其全屏展开

安装

  1. 安装 Cocoapods
  2. 在 Podfile 中添加 pod 'UIExpandableCVCellKit'
  3. 在包含 Podfile 的项目目录中使用终端运行 pod install

设置

所需:UICollectionViewController

  • 让您的 UICollectionView 扩展 ExpandableCVProtocol

  • 将此行添加到 viewDidAppear(_ animated:) 代理函数中:collectionView.isScrollEnabled = (isCellOpen) ? false : true

    这确保在您在应用之间切换时,当您在应用之间切换时,滚动被设置为正确的设置

  • 在 collectionView(_:collectionView:, cellForItemAt indexPath:) 中 dequeue 单元格,然后创建 ExpandedCellViewModel 并使用 ExpandableCVCellProtocol.configure(withOptions options: [ExpandableCellViewProperties]?, expandableCVProtocol: ExpandableCVProtocol?) 函数将其传递给单元格,这将帮助单元格配置所需的所有设置。

    • 您可以进一步调整单元格展开的不同设置。这在您的 collectionView 在容器中且小于您想要展开到的视图时非常有用。使用相应的枚举并添加相关值,然后将所有枚举作为一个数组传递到选项中。
  • 在collectionView(_ collectionView:, didSelectItemAt indexPath:)方法中实现animateCellOpen(indexPath:)来确保单元格可以正常打开。这是一个强制实现。

UICollectionViewCell

  • 让你的UICollectionViewCell扩展ExpandablerCVCellProtocol

  • 在你初始化器init(frame:)和init(coder:)中添加setupPanGesture(selector: Selector),并使用你自己的手势函数。我通常将其命名为cellGestured(),在这个@objc函数中,我添加了默认的cellGesturedLogic()函数。当然,如果需要,你也可以覆盖并编写你自己的手势逻辑。

可选

  • 你可以选择实现以下函数来模拟单元格打开、关闭或快速返回的动画,或者编写你自己的代码。

    • func openCellHandler() -> (handler: Handler?, completion: Handler?, isAnimated: Bool)
    • func closeCellHandler() -> (handler: Handler?, completion: Handler?, isAnimated: Bool)
    • func snapBackCellHandler() -> (handler: Handler?, completion: Handler?, isAnimated: Bool)

    以下是openCellHanlder()或任何其他可选处理函数的示例

     func openCellHandler() -> (handler: Handler?, completion: Handler?, isAnimated: Bool) {
    
     	let animations = {
     		// your code that you would like animated into this block or any code you would like handled
     	}
    
     	let completion = {
     		// any code you would like to run after the animations/handler
     	}
    
     	return (handler: animations, completion: completion, isAnimated: true)
     }
    

可选

如果你想展示和隐藏状态栏以展示和隐藏可展开的collectionViewCell,请执行以下操作

  1. 在您的UICollectionView类中

添加

override var prefersStatusBarHidden: Bool {
	return statusBarShoudlBeHidden
}

override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
	return .slide
}

如果你喜欢,你可以选择另一种类型的动画

  1. 可选的,你可以使用func animateStatusBar(duration: TimeInterval)在需要时隐藏或显示状态栏。然而,在运行此函数之前,你应该设置statusBarShouldBeHidden设置。

有关示例项目,请参阅https://github.com/yungdai/AppStoreAnimationDemo