Search code examples
iphoneobjective-cuiviewcore-animation

how to bring another screen on top of current view, iphone


When playing music in the iphone, at the main screen with title of "Song", there is a button called Stored located on the top left corner and "Now Playing" on the top right corner. If we click "Store", there is an animation to show Store view to the main screen. My question is how we can do such an animation . Any comments are welcomed here. Thanks


Solution

  • That's a really tricky question - the animation you're describing is used by iOS to indicate to the user that they are switching applications. I'm going to assume that you want to reproduce this animation within your own application. It's probably not a good idea to do that, since it would confuse the user, but for academic reason's, let's explore.

    Let's say you have two views that you want to switch. You've got a couple of different options in how to animate their transition:

    • Use standard built-in animations to switch views (typically, either UINaivationController or presentModalViewController:animated:).
    • Use implicit animations on the views. This isn't difficult, breaks the Model-View-Controller paradigm unless both views are managed by the same view controller.
    • Use Core Animation animations on the CALayer's of the views. This also breaks MVC.

    As you move down the list, you get more control over the animations, but also have to do more work. To recreate the animation you're interested in, you'd have to use the last option, since the animation is 3D and quite complex.

    To learn more about how to transition from one view to another using Core Animation, look at this example on github. It will give you an idea of what's involved and point you in the right direction to create the effect you're looking for.