Custom animated transition - view in/view out

I have a custom transition written in Swift where the dismissed view goes out as the presented view comes in from the side.

Now I want this same effect, but I want the presented view to come in from the top and the dismissed view go out at the bottom.

My code looks like this:

func animateTransition(transitionContext: UIViewControllerContextTransitioning){

    let container = transitionContext.containerView()
    let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
    let toView = transitionContext.viewForKey(UITransitionContextToViewKey)

    let offScreenRight = CGAffineTransformMakeTranslation(container.frame.width, 0)
    let offScreenLeft = CGAffineTransformMakeTranslation(-container.frame.width, 0)


    if self.presenting == true{
        toView?.transform = offScreenLeft
    }else{
        toView?.transform = offScreenRight
    }

    container.addSubview(toView!)
    container.addSubview(fromView!)

    let duration = self.transitionDuration(transitionContext)

    UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.8, options: nil, animations: {

        if self.presenting == true{
            fromView?.transform = offScreenRight
        }else{
            fromView?.transform = offScreenLeft
        }
        toView?.transform = CGAffineTransformIdentity

        }, completion: { finished in

            // tell our transitionContext object that we've finished animating
            transitionContext.completeTransition(true)

    })
}

I thought this would be easy, as my logic tells the way to do this is to change from "width" to "height" in the toView, and fromView, but this does not work, and just creates the same effect as before, but it seems to skip one empty (black) view.

Any suggestions on how to achieve the desired effect would be appreciated.

The buggy code:

func animateTransition(transitionContext: UIViewControllerContextTransitioning){

    let container = transitionContext.containerView()
    let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
    let toView = transitionContext.viewForKey(UITransitionContextToViewKey)

    let offScreenUp = CGAffineTransformMakeTranslation(container.frame.height, 0)
    let offScreenDown = CGAffineTransformMakeTranslation(-container.frame.height, 0)


    if self.presenting == true{
        toView?.transform = offScreenDown
    }else{
        toView?.transform = offScreenUp
    }

    container.addSubview(toView!)
    container.addSubview(fromView!)

    let duration = self.transitionDuration(transitionContext)

    UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0.8, options: nil, animations: {

        if self.presenting == true{
            fromView?.transform = offScreenUp
        }else{
            fromView?.transform = offScreenDown
        }
        toView?.transform = CGAffineTransformIdentity

        }, completion: { finished in

            // tell our transitionContext object that we've finished animating
            transitionContext.completeTransition(true)

    })
}

Answers


You are still trying to translate in the X Coordinate. Try doing the translation in the Y coordinate.

let offScreenUp = CGAffineTransformMakeTranslation(0,container.frame.height)
let offScreenDown = CGAffineTransformMakeTranslation(0,-container.frame.height)

Need Your Help

How to write 3g Application in Linux

linux embedded-linux 3g electronics

Please explain steps of how to write program in Linux for 3g. I am a newbie to 3G standards thats why I need to know how to make an application in Linux for my 3G device, suppose that 3G device is ...

Read a record selected in DataGridView table and read through info of that record into fields that is not shown in the table

c# winforms visual-studio datagridview .net-3.5

Note: Some of the code included below has already been used in some of my other questions but regarding other issues. I have also edited most of the post to cause less confusion!

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.