SPM supported

DAExpandAnimation

一个自定义的模态转场动画,在呈现控制器时使用展开效果,同时将呈现器的剩余部分滑出。

截图

DAExpandAnimation

安装

只需将 Sources/DAExpandAnimation/DAExpandAnimation.swift 文件复制到你的项目中即可。

Swift Package Manager

DAExpandAnimation 也可以通过 Swift Package Manager 获取。

.package(url: "https://github.com/ifitdoesntwork/DAExpandAnimation.git", from: "1.0.0")

使用

尝试一下示例项目!

让你的视图控制器遵循 UIViewControllerTransitioningDelegate。 可选地设置 collapsedViewFrame, expandedViewFrame, slidingPartanimationDuration

private let animationController = DAExpandAnimation()

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    guard let selectedCell = sender as? UITableViewCell else {
        return
    }
    
    let toViewController = segue.destination
    toViewController.transitioningDelegate = self
    toViewController.modalPresentationStyle = .custom
    toViewController.view.backgroundColor = selectedCell.backgroundColor
    
    animationController.collapsedViewFrame = {
        selectedCell.frame
    }
    animationController.animationDuration = Constants.demoAnimationDuration()
}
    
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    animationController
}

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    animationController
}

协议

采用 DAExpandAnimationPresentingViewAdapter 提供以下可选的代理方法,用于定制呈现器的 UX (用户体验)。

/// Determines whether the animations include sliding the presenter's view apart.
/// Defaults to `true`.
var shouldSlideApart: Bool { get }

/// Notifies the presenter's view adapter that animations are about to occur.
func animationsWillBegin(in view: UIView, presenting isPresentation: Bool)

/// Notifies the presenter's view adapter that animations are just completed.
func animationsDidEnd(presenting isPresentation: Bool)

采用 DAExpandAnimationPresentedViewAdapter 提供以下可选的代理方法,用于定制新视图控制器的呈现。

/// Gives the presented view adapter a chance to prepare
/// the expanding `view` before the animations.
func prepare(expanding view: UIView)

/// Gives the presented view adapter ability to change
/// properties of the expanding `view` alongside the animations.
func animate(expanding view: UIView)

/// Gives the presented view adapter ability to clean the expanded `view` up
/// after the animations are performed.
func cleanup(expanding view: UIView)

/// Gives the presented view adapter a chance to prepare
/// the collapsing `view` before the animations.
func prepare(collapsing view: UIView)

/// Gives the presented view adapter ability to change
/// properties of the collapsing `view` alongside the animations.
func animate(collapsing view: UIView)

/// Gives the presented view adapter ability to clean the collapsed `view`
/// up after the animations are performed.
func cleanup(collapsing view: UIView)