How would I go about presenting a \"half view\" controller over the top of main view controller?
Requirements: - Present a second view controller that slides over the to
One way to do it is to add the "half modal" controller as a child view controller, and animate its view into place. For this example, I created the "half modal" controller in the storyboard with a frame that's half the height of a 4" iPhone screen. You could use more dynamic methods to account for different screen sizes, but this should get you started.
@interface ViewController ()
@property (strong,nonatomic) UIViewController *modal;
@end
@implementation ViewController
- (IBAction)toggleHalfModal:(UIButton *)sender {
if (self.childViewControllers.count == 0) {
self.modal = [self.storyboard instantiateViewControllerWithIdentifier:@"HalfModal"];
[self addChildViewController:self.modal];
self.modal.view.frame = CGRectMake(0, 568, 320, 284);
[self.view addSubview:self.modal.view];
[UIView animateWithDuration:1 animations:^{
self.modal.view.frame = CGRectMake(0, 284, 320, 284);;
} completion:^(BOOL finished) {
[self.modal didMoveToParentViewController:self];
}];
}else{
[UIView animateWithDuration:1 animations:^{
self.modal.view.frame = CGRectMake(0, 568, 320, 284);
} completion:^(BOOL finished) {
[self.modal.view removeFromSuperview];
[self.modal removeFromParentViewController];
self.modal = nil;
}];
}
}