Easy partial screen modals on iOS
This post was written by Anders from Bump's iOS team.
Say you would want to present a modal view on an iPhone but you don't want it to be full screen. What do you do? Well, there is always the option of just not using presentModalViewController:animated: and performing the animations yourself which also in turn means maintaining view and controller hierarchy yourself.
You could of course subclass UINavigationController and encapsulate all that complexity in a subclass. That would of course mean that you would need to update your code in all places that use the UINavigationController. Another similar approach would be to subclass UIView and override setFrame: to not allow the frame to be set to full screen. Again, that would mean updating all relevant views to subclass your new UIView subclass with the setFrame: logic.
A different approach which lets you maintain your code pretty much unchanged requires you to change the way UINavigationController itself behaves. The following solution lets you set the frame of your UINavigationControllers view which will then be maintained even if a modal view controller is presented.
All you need to to is call a static initializer method on this new NPNavigationController class:
[BPNavigationController setup];
Now you can set the UINavigationControllers view frame. Like so:
navigation.view.frame = CGRectMake(0.0f, 20.0f, 320.0f, 440.0f);
If at any later point you present a modal view controller in a navigation controller that modal view controller will only be as big as the frame of the navigations controllers view.
How is this magic achieved? Behold: