美文网首页
断头台动画

断头台动画

作者: Jianhong_z | 来源:发表于2016-06-16 11:47 被阅读41次

最近在做的一个小项目需要用到这种断头台效果,后面在github上找到了对应的代码。
https://github.com/Yalantis/GuillotineMenu
遗憾的是在菜单页面present一个ViewController的话,在这个ViewController dismiss后,菜单按钮会移到后面。
后面采用了一种取巧的方法,分别在下面的两处代码进行修改:

    private func animateDismissal(context: UIViewControllerContextTransitioning) {
        menu = context.viewControllerForKey(UITransitionContextFromViewControllerKey)!
        if menu.navigationController != nil {
            let toVC = context.viewControllerForKey(UITransitionContextToViewControllerKey)!
            context.containerView()!.addSubview(toVC.view)
            context.containerView()!.sendSubviewToBack(toVC.view)
        }
        if UIDevice.currentDevice().orientation == .LandscapeLeft || UIDevice.currentDevice().orientation == .LandscapeRight {
            updateChromeView()
            menu.view.addSubview(chromeView!)
        }
        
        let toVC = context.viewControllerForKey(UITransitionContextToViewControllerKey)
        toVC?.beginAppearanceTransition(true, animated: true)

        animationDelegate?.animatorWillStartDismissal?(self)

        //dimiss的时候转移到context.containerView()
        if containerMenuButton != nil {
            containerMenuButton!.removeFromSuperview();
            context.containerView()!.addSubview(containerMenuButton!)
        }

        animateMenu(menu.view, context: context)
    }
//MARK: - UIDynamicAnimatorDelegate protocol implementation
extension GuillotineTransitionAnimation: UIDynamicAnimatorDelegate {
 
    func dynamicAnimatorDidPause(animator: UIDynamicAnimator) {
        if self.mode == .Presentation {
            self.animator.removeAllBehaviors()
            menu.view.transform = CGAffineTransformIdentity
            menu.view.frame = animationContext.containerView()!.bounds
            anchorPoint = CGPointZero
        }

        chromeView?.removeFromSuperview()
        animationContext.completeTransition(true)
        
        if self.mode == .Presentation {
            let fromVC = animationContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
            fromVC?.endAppearanceTransition()
            animationDelegate?.animatorDidFinishPresentation?(self)

            //present 结束的时候,把view转移到menu上
            if containerMenuButton != nil {
                containerMenuButton!.removeFromSuperview();
                menu.view.addSubview(containerMenuButton!);
            }

        } else {
            let toVC = animationContext.viewControllerForKey(UITransitionContextToViewControllerKey)
            toVC?.endAppearanceTransition()
            animationDelegate?.animatorDidFinishDismissal?(self)

        }
        //Stop displayLink
        displayLink.paused = true
    }
}

这样也可以在菜单页面present出 一个新的ViewController了。

相关文章

  • 断头台动画

    最近在做的一个小项目需要用到这种断头台效果,后面在github上找到了对应的代码。https://github.c...

  • 查理一世一一英国历史上第一个被公开处决的国王

    1649年1月30日早晨,在白厅宴会厅前搭起了断头台,有一个特殊的犯人将被押上断头台,实行死刑。 断头台下已经围观...

  • 断头台

    最怕你失去心智, 却还在沾沾自喜。 最怕你没有勇气, 却还在不明就里。 最怕你早就放弃, 却还在深信不疑。 你上了...

  • 断头台

    陈三儿当上公司老板之后,没事儿喜欢研究欧洲历史,特别是大革命那段儿。 他和我说,断头台是杀人史上最伟大的发明之一,...

  • 断头台

    在喧腾的冷嘲中 我,走上断头台 干柴堆起自画像 大半生的诗稿横尸周遭 从烈焰和烟灰里 一双双冰层的黑窟窿 穿过火苗...

  • 断头台

    0 很多年以前,当我提出把断头台的切面改成三角形的时候,我一定没有想到,第一个体验这种断头台的人,竟然就是我自己。...

  • 断头台

    神父挽着囚徒的手,昂首立于囚车内。他的十字架,挂在囚徒胸口。 囚徒亦昂首,仿佛要赴一场神圣的约会。他甚至有些急不可...

  • 断头台

    北冥刑场,夕阳余晖。 木易看着东三天浑身血迹,面色苍白地拖着重重的脚铐来到断头台。 他怎么都想不明白,这样一个三十...

  • 关于“断头台”的随想

    “断头台”绝不是一个吉利的词汇,但是追溯到“断头台”的起源,它的出现却是出于人道主义的关怀。 在法国...

  • DouHua周推,Viva la Vida,是让路易十六直面断头

    ​1793年1月21日,巴黎革命广场上,法国国王路易十六被送上自己设计的断头台上。让人感到惊讶的是,走上断头台的他...

网友评论

      本文标题:断头台动画

      本文链接:https://www.haomeiwen.com/subject/ggemdttx.html