vance
vance

Reputation: 1097

How would you implement [UIViewController presentModalViewController]?

I have to customize the transition between 2 different UIViewController and for that I would like to re-implement [UIViewController presentModalViewController...]. What is inside this function? How does it work? What does it do?

Thanks a lot, Vance

Upvotes: 1

Views: 1041

Answers (1)

PeyloW
PeyloW

Reputation: 36762

The -[UIViewController presentModalViewController:animated:] do allot of magic behind the scenes.

For my app Tweet Note I wanted to present modal view controllers by animating the new view from the backside of a view in a shelf. More or less what iBooks does. I tried to override the default implementation but ended up doing it in a multi step solution that works without ugly hacks and caveats:

  1. Instantiate the new view controller.
  2. Apply the transform to the new view controller's managed view, so that it starts in it's initial location.¨
  3. Start animating the view into untransformed "normal" position.
  4. Wait for animation to finish, and do as a unit:
    • Remove the view you just animated from screen.
    • Call [self presentModalViewController:vc animated:NO].

That last step is important! After your transition animation completes present the modal view controller as normal but without animation, and will appear to the user just as if you did a proper animated presentation.

Dismissing with your custom transition is more or less doing the same thing but in reverse order.

Upvotes: 1

Related Questions