Custom View Controller Transitions in Landscape

Recently, Jerry wrote about a really cool view controller transition we put together, SMLBookshelfTransition. As you can tell from that post, we’re really excited about all the possibilities this new API provides. You might have noticed though that Jerry made a point of saying he doesn’t usually write about brand-new API, because of the difficulty of doing it authoritatively.

Welp.

Being excited, we spent some time putting custom transitions into the project we’re working on. Everything looked good… until we rotated the device.

Turns out custom view controller transitions just plain don’t work in landscape. It seems that the system doesn’t apply the correct rotation transforms to the views involved: the container view that the transition context creates is always in portrait, even though the transitioning view controllers’ views may not be.

broken.m4v

Solutions?

If you google around enough, you may eventually arrive at this Developer Forums thread (Apple Developer account required). It suggests some potential workarounds, involving shuffling transforms around between the views involved. Make no mistake: this is seriously hacky, and likely to break with a future iOS update. Using these can make the transition look okay, but in my testing, rotations are still broken after the transition completes:

broken4.m4v

Instead, we took our own app back to using the slightly older-school view controller containment design. Making the presented controller a child of the presenting controller entails a bit more work to make sure the views all appear where they should, but it’s fully supported, uses the API as it’s designed to be used, and works as expected.

Conclusion

As far as I can tell, this stuff is just plain broken. I can’t in good conscience recommend that anyone use custom view controller transitions in any app that might ever need to go to landscape. Despite how cool the API is, it’s probably best to avoid it entirely in shipping projects until Apple fixes it in a new version of iOS.

Joel Kraut

About Joel Kraut

Developing on Apple platforms for, holy shit, over ten years now. Find me on linkedin and twitter. My personal website is foon.us.
This entry was posted in Explanation and tagged , , , , . Bookmark the permalink.

5 Responses to Custom View Controller Transitions in Landscape

  1. Pingback: Custom UIViewController Transitions | Teehan+Lax

  2. Pingback: Bookshelf View Controller Transition For iOS 7 | ultrajoke

  3. senior says:

    I’ve filed a bug report for this. Feel free to dupe rdar://15916308

  4. Robert says:

    I think the WWDC mentioned that animations using CoreAnimation API as opposed to the UIKit API are not supported i.e. animating transform, instead of affineTransform. I might be wrong, they could have been talking about interactive transitions only, and obviously you cant do your effect without the 3D transforms. However, the simple animations I have done in UIKIt work ok in landscape, might be best not to count them out entirely! E.g. https://github.com/rsaunders100/TestInteractiveTransition

  5. leechbite.com says:

    It can be fixed by transforming your CGRect based on the current view’s transform.
    See:
    http://stackoverflow.com/a/23082183/3535680
    I used it in my app and works pretty well on animations on any orientation.

Leave a Reply

Your email address will not be published. Required fields are marked *