Curling a UIView Up/Down with Swift

I had a problem creating the page curling effect between two views. The solution suggested on StackOverFlow is to use a container that uses auto layout for the two transitioning views, which do not use autolayout. Here’s what the problem looked like:

Here’s what the views should look like:


I committed the working project to my Swift Github repo: under the Xcode project TransitionWithView. Here’s the main functionality:

    func curlUp() {
        let transitionOptions = UIViewAnimationOptions.TransitionCurlUp
            toView: cardBack,
            duration: 5.0,
            options: transitionOptions,
            completion: { _ in
                let transitionOptions = UIViewAnimationOptions.TransitionCurlDown

                    toView: self.cardFront,
                    duration: 5.0,
                    options: transitionOptions,
                    completion: { _ in


    func buildView() {

        let height = 100
        let width = 100

        container = UIView()
        container.backgroundColor = UIColor.blackColor()
        cardBack = UIView(frame: CGRectMake(0, 0, CGFloat(width), CGFloat(height)))
        cardBack.backgroundColor = UIColor.redColor()
        cardFront = UIView(frame: CGRectMake(0, 0, CGFloat(width), CGFloat(height)))
        cardFront.backgroundColor = UIColor.greenColor()

        let viewDictionary:Dictionary = ["container": container]

        let metrics:Dictionary = ["width": width, "height": height]

        let h0Constraint = "H:[container(==width)]"
        let v0Constraint = "V:[container(==height)]"
        addStandardConstraints(self.view, constraint: h0Constraint, viewDictionary: viewDictionary, metrics: metrics)
        addStandardConstraints(self.view, constraint: v0Constraint, viewDictionary: viewDictionary, metrics: metrics)
        centerViewXY(self.view, child: container)
        NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: "curlUp", userInfo: nil, repeats: false)