小编Fay*_*yer的帖子

UINavigationBar 颜色动画与推送动画同步

我想在具有不同UINavigationBar背景颜色的视图之间实现流畅的动画。嵌入的视图具有相同的背景颜色UINavigationBar,我想模仿推/弹出过渡动画,如:

在此处输入图片说明

我准备了自定义过渡:

class CustomTransition: NSObject, UIViewControllerAnimatedTransitioning {

    private let duration: TimeInterval
    private let isPresenting: Bool

    init(duration: TimeInterval = 1.0, isPresenting: Bool) {
        self.duration = duration
        self.isPresenting = isPresenting
    }

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return duration
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let container = transitionContext.containerView
        guard
            let toVC = transitionContext.viewController(forKey: .to),
            let fromVC = transitionContext.viewController(forKey: .from),
            let toView = transitionContext.view(forKey: .to),
            let fromView = transitionContext.view(forKey: .from)
        else {
            return
        }

        let rightTranslation = …
Run Code Online (Sandbox Code Playgroud)

uinavigationbar ios custom-transition swift

2
推荐指数
1
解决办法
2044
查看次数

标签 统计

custom-transition ×1

ios ×1

swift ×1

uinavigationbar ×1