A simple, lightweight UIViewController Category for creating a semi modal / push back transition.
This code was originally a fork of kentnguyen's KNSemiModal category.
Update (July 14, 2013): Added a push/dismiss Modal view example. Note: The modal view is actually hidden from the main view. To view it, open the storyboard, click the main view controller, and you'll see a white box between the first responder (red cube) and Exit segue (green exit square).
Just drag the white box (which is the view) onto the viewcontroller to edit/view it. its up to you if you want to put it back (you can just drag it from interface builder to the bottom bar and it will automatically hide).
- Refactored a lot of the animation code and split things out into more manageable chunks.
- Added blocks and GCD
- Replaced the screenshot resize for the push back animation transition with just a simple resizing of the main view.
- Removed a bunch of other logic I wasn't needing
- Rewrote almsot all of the non-CATransform3DTranslate methods/logic
- Currently, its now just under 220 lines (from 348)
- I'm working on some new transition styles so that you can choose which transition to use
- Removed "presentSemiView"
- the Dismiss block for the present methods (temporarily).
- Removed calls to "shouldRasterize" and "rasterizationScale".
- Removed all of the traversal searches for the parentview.
- Removed the shadow layers
- All objc_runtime properties
- All of the define methods
- All of the subclasses/categories
- Removed the "options" param
- Removed the screenshot creation
- The transform3d logic for scaling/rotating
- callback methods for completion
- some of the animation routines
- the overlay view
- There is not a paramater to define where the presented view should end up at. Instead, you'll have to either add it, or update the keLBeeSizePresentedViewHeight value (all views will then end up with this height)
- There is no scaling of the view. This is easy to add and is something I'll be adding soon enough (I need it myself).
- There is only one transition sequence for the modal popup: bottom to top (show), top to bottom (hide). I'll be adding more as I need them myself.
- Logic to dismiss the modal when tapping the background is not there yet - in the works
- I'm sure there is some other stuff too, so feel free to make a suggestion or add it and submit a pull request!
Finally, here is a quick demo of how to use it (this is alsoincluded project under, Example).
It includes 2 buttons: a Push controller button and a Modal button.
#import "MainViewController.h"
#import "ModalViewController.h"
#import "UIViewController+eLBeePushBackController.h"
@interface MainViewController() <ModalVCDelegate>
@property (nonatomic, weak) IBOutlet UIView *modalView;
@end
@implementation MainViewController
-(IBAction)pushBackVCDelegateShouldDismissController:(id)sender {
ModalViewController *controller = (ModalViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"ModalViewControllerSBID"];
controller.delegate = self; // This is not necessary - is good to just let your main view handle presenting/dismissing
[self presentPushBackController:controller];
/*
// Example using withCompletion
[self presentPushBackController:controller withCompletion:^{
NSLog(@"The View was pushed and has completed!");
}];
*/
}
-(void)pushBackVCDelegateShouldDismissController:(ModalViewController *)controller {
controller.delegate = nil;
[self dismissPushBackController:controller];
/*
// Example using withCompletion
[self dismissPushBackController:controller withCompletion:^{
NSLog(@"The View was pushed and has completed!");
}];
*/
}
// Modal View Example:
-(IBAction)presentPushBackModalViewBtn:(id)sender {
[self presentPushBackView:self.modalView withCompletion:^{
NSLog(@"Modal View was presented!");
}];
}
-(IBAction)dismissModalViewBtn {
[self dismissPushBackViewWithCompletion:^{
NSLog(@"Modal View was dismissed!");
}];
}
@end
#import <UIKit/UIKit.h>
@class ModalViewController;
@protocol ModalVCDelegate <NSObject>
-(void)pushBackVCDelegateShouldDismissController:(ModalViewController *)controller;
@end
@interface ModalViewController : UIViewController
@property (nonatomic, weak) id <ModalVCDelegate> delegate;
@end
#import "ModalViewController.h"
@interface ModalViewController()
-(IBAction)dismissAction;
@end
@implementation ModalViewController
-(IBAction)dismissAction {
[self.delegate pushBackVCDelegateShouldDismissController:self];
}
@end
This is released under the MIT License - checkout LICENSE for more information.
Thanks, hope you find this useful!!
Stackoverflow - UIView Cloning
Website: http://phpadvocate.com/
LinkedIn: http://www.linkedin.com/in/jhibbard/
Twitter: https://twitter.com/infolock