1
votes

In my app are three view controllers; White, red, and blue. White's is the main view of the app.

On button taps, White modally presents Red. Red modally presents blue. All is well. Blue has e.g. some form for the user to complete, then the user taps Dismiss on Blue.

Three view controllers

Blue would like to return the user to the main UI, white. When the user taps Dismiss, this runs:

@IBAction func didTapDismissBoth(sender: AnyObject) {
    let red = presentingViewController!
    let white = red.presentingViewController!
    white.dismissViewControllerAnimated(true, completion: nil)
}

Both Red & Blue do indeed dismiss, but Blue vanishes immediately and Red is seen doing the dismissal animation! The flash of red is visually jarring and easily visible in the Simulator when Slow Animations are on.

I would rather see Blue sliding gracefully off screen to reveal White.

Can I prevent Red from rearing its ugly head when returning to White from Blue?

2

2 Answers

0
votes

I was able to simulate the effect I want by (in IB) setting Red's presentation style as "over current context". This tells UIKit to keep Red's parent's (White) view around, so if e.g. Red has transparency in its view, White would show through.

In the dismissal process, I set Red to completely transparent, and animate blue away.

@IBAction func didTapDismissBoth(sender: AnyObject) {
    let red = presentingViewController!
    let white = red.presentingViewController!
    red.view.alpha = 0 // Red presents "over current context" so white's view still exists. White's view will show through this transparent red
    red.dismissViewControllerAnimated(true, completion: { // dismiss blue, revealing transparent red & white showing through
        white.dismissViewControllerAnimated(false, completion: nil) }) // dismiss red with no animation
}

Though this hides the problem of Red flashing, it doesn't explain the dismissal animation process; and means White's view stays around unnecessarily.

0
votes

I would use unwind segues for this. You are using storyboards, why not take advantage of that. Just create an unwind segue from the blue view controller to the white one and you are done.