views:

386

answers:

1

I'm using a modal view controller to allow a user to select an address book entry and email address. The ABPeoplePickerNavigationController object is displayed via presentModalViewController:animated:

[self presentModalViewController:picker animated:YES];

What I want to do is keep the modal dialog up, but when the user selects the email address, it should cross-fade to a different controller that displays a message composition window.

I've tried various approaches in peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier: to dismiss the picker and set my custom composition controller as the modal view. I can do it any number of ways, but never does it fade smoothly from the picker to the composition controller -- unless I make the composition controller a modal dialog of the picker, in which case the picker re-appears when I dismiss the composition controller. I don't want that, either.

There must be some way to smoothly replace one controller and its view with another controller and its view, all within the context of a modal dialog, and preferably with a cross fade. Suggestions greatly appreciated.

A: 

Add the composition controller as a subview of your picker. Set its alpha to 0 so it is transparent. Then use an animation block to gradually animate its alpha to full:

// Initially set alpha to 0    
[myCompositionView setAlpha:0];

// Later when you want to show the view, animate the alpha to 1.0
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[myCompositionView setAlpha:1.0];
[UIView commitAnimations];
pheelicks
But if I do that, when I finish with the composition controller, the picker will reappear and also need to be dismissed. What I want is for the picker to seem to be replaced with the composition controller, so that when I dismiss the composer what I see is the original parent -- no picker at all.
Theory
As the composition view is a subview of the picker, when you dismiss the picker the composition view will also disappear. Just make sure that the action which dismisses the compositon view tells your parent view to dismiss the modal viewcontroller
pheelicks
Ah! Thanks for that extra added insight. I've now added a delegate interface for the composer, and am assigning the main view controller as the delegate. It then implements the `composeViewControllerDidFinish:` method that removes the picker modal view, thus dismissing them both. FWIW, I'm not using an animation block but setting `modalTransitionStyle` to `UIModalTransitionStyleCrossDissolve`, presenting the compose window, and then setting it back to `UIModalTransitionStyleCoverVertical`. This allows the fade to the composer to work, and when it's dismissed it slides down again. Works great!
Theory