Monday, June 22, 2009

3.0's presentModalViewController:withTransition:

In 3.0 the algorithm -presentModalViewController:animated: is changed. The most prominent change I can see is that the modal view controller will always use the application frame instead of the parent view controller's frame. This breaks modal table theming in GriP. Fortunately, probably Apple also thinks the change to too drastic, they've also provided -_legacyPresentModalViewController:withTransition: that uses the old algorithm, so until iPhoneOS 4.0 comes we can still ignore this problem.

The 3.0's -presentModalViewController:animated: calls the undocumented method -presentModalViewController:withTransition: as a backend, where the 2nd parameter "transition" is an integer. For official SDK there're 5 official transitions (present and dismiss count as 2): Slide up/down, Flip to left/right, and cross fade.

But -presentModalViewController:withTransition: supports a bit more:
ParameterTransition
0None
1Push from right to left
2Push from left to right
3Push from bottom to top
6Fade
7Push from top to bottom
8Slide from bottom to top
9Reveal from top to bottom
10Flip from left to right
11Flip from right to left

4 comments:

  1. This is great, I've been battling with a crashing app due to these changes. Do you know how to dismiss the modal view controller after this? It seems it won't respond to the standard dismissModalViewControllerAnimated:

    ReplyDelete
  2. @Pieter:

    dismissModalViewControllerWithTransition: ?

    ReplyDelete
  3. For more details look here:
    http://ericasadun.com/iPhoneDocs220/interface_u_i_view_controller.html

    To avoid the warnings generate categories like that:
    // allow transitions between ViewControllers
    @interface UIViewController(extended)
    - (void)presentModalViewController:(id)fp8 withTransition:(int)fp12;
    - (void)dismissModalViewControllerWithTransition:(int)fp8;
    @end

    I have a file called undocumented for these... ;)

    Live long and prosper,
    Cy

    ReplyDelete
  4. (Short update) Now I am using the long way:

    // allow transitions between ViewControllers
    typedef enum {
    UIViewControlerAnimationTransitionNone = 0,
    UIViewControlerAnimationTransitionFade = 6,
    UIViewControlerAnimationTransitionPushFromTop = 7,
    UIViewControlerAnimationTransitionPushFromRight = 1,
    UIViewControlerAnimationTransitionPushFromBottom = 3,
    UIViewControlerAnimationTransitionPushFromLeft = 2,
    UIViewControlerAnimationTransitionSlide = 8,
    UIViewControlerAnimationTransitionReveal = 9,
    UIViewControlerAnimationTransitionFlipFromLeft = 10,
    UIViewControlerAnimationTransitionFlipFromRight = 11
    } UIViewControllerAnimationTransition;

    @interface UIViewController(extended)
    - (void)dismissModalViewControllerWithTransition:(UIViewControllerAnimationTransition)transition;
    - (void)presentModalViewController:(id)viewController withTransition:(UIViewControllerAnimationTransition)transition;
    @end

    LLAP, Cy

    ReplyDelete