KNSemiModal Category for iOS

Posted: May 4th, 2012 | Author: | Filed under: iOS | 7 Comments »

UIViewController+KNSemiModal Category

UIViewController+KNSemiModal is an effort to make a replica of semi-modal view with pushed-back stacked animation found in the beautiful Park Guides by National Geographic app. You can see this original semi-modal view below.

The pictures don’t really describe enough the cool factor of the implementation. You can download a short video I recorded to see the effect : demo video (1.3MB, .mov)

Why I do this?

Please read my discussion in a separate blog post. I highlighted some issues with the current implementations of the modal view and how I think it can be better

Drop-in installation

This library (ARC) is designed as a Category to UIViewController so you don’t have to subclass and you can simply drop in any project and it will just work!

Copy 2 category files UIViewController+KNSemiModal to your project and add this import line at the top of your current ViewController file

#import "UIViewController+KNSemiModal.h"

You can prepare your UIView * myView with all the controls and subviews that you need before presenting it with

[self presentSemiModalView:myView]

Another convenient method is presenting a separate ViewController class by calling

[self presentSemiViewController:myOtherViewController]

However, note that this myOtherViewController need to be retained manually by assigning it to a @property or ivar.

TODO

  • Landscape support.
  • Maybe iPad support, it will be quite different though.
  • Fake ivar with Associative References to retain ViewController
  • Subclass branch (anyone can spare the time?)

Source code

https://github.com/kentnguyen/KNSemiModalViewController


  • http://twitter.com/mave99a Robert Mao

    Screenshot is slow, that will cause a delay which reduce the user experience. Why not directly animate on the view’s layer directly ?

  • Bharani

    It showing some error like “@ missing” in UIViewController+KNSemiModal.h can you please give me the solution i like your work i need to implement in my app but i can’t show demo to my TL Please provide me the solution

  • Csmoak

    Has this been used in a app submitted to App store? Just want to make sure it doesnt get rejected due to using undocumented SDK methods.

  • Filipe

    Hi Kent,
    First, thanks for this class. Second, you can use this wit Storyboard project?I can’t, the modal view open, but the close button always return this error:”Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Defaults must have been set when accessing options.’

    *** First throw call stack:”

    • taurus

      same problem here! Did you resolve it in someway?

      • http://www.etudoounada.com.br/ Filipe Bragança

        Unfortunately I can’t solve my problem, so I give up and change my app. If you can solve, please share with me???

        • Kent Nguyen

          Do send me some codes so that I can reproduce the issue you mentioned