1
votes

My app is setup using a UINavigationController for all of the navigation. I am wanting to use a modal transition to present a specific view controller in the app. The thing is that I want to keep that new VC embedded inside of the navigation controller, but just that one view needs to use a modal animation rather than push.

How can I go about implementing this modal animation/transition on a single view controller within the UINavigationController?

Keep in mind that after this modal animation happens there will be buttons on that page that will proceed to work in line with a standard UINavigationController push animation.

6
forget that there is something like modal and do a presentModalView. that should work.Kunal Balani
In iOS 7 presentModalViewController is deprecated and when I perform that method it takes that view out of the UINavigationController.BlueBear
I mean [self.navigationController presentViewController:yourViewController ... ]Kunal Balani
modal view is always fullscreen, however you can change the presentationstyle.Kunal Balani

6 Answers

2
votes

With iOS7, this is possible using the new custom transitioning API. You can find more information here: http://www.objc.io/issue-5/view-controller-transitions.html

You create an animation controller (interactive or otherwise), and pass it in the appropriate method of the navigation bar delegate. In your animation controller, you perform the custom animation using UIView animation API. In your case, the animation should perform a slide from bottom into place for forward animation, and slide from place to bottom for reverse animation. If you support interactive animation, you can even control the curve of the animation in relation to the finger slide.

4
votes
ITviewViewController *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"vc"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:Nil];

Replace the pseudo code with your view controller names.

1
votes

Modal view by default is full screen. You need to change presentation style to show navigationBar

EDIT : This only works for iPad. For iPhone you can use MZformsheet or Kentnguyen to get semi modal behavior

MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease]; 

targetController.modalPresentationStyle = UIModalPresentationFormSheet;

targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter 

[self presentModalViewController:targetController animated:YES];


targetController.view.superview.frame = CGRectMake(0,44/*navigation bar's height*/,height, width);//it's important to do this after 
// use full screen height and width here

targetController.view.superview.center = self.view.center;
0
votes

Use this line not presentModelViewController

[self presentViewController:vc animated:YES completion:Nil];  
0
votes

Maybe something like this will work for you (self is UINavigationController):

- (void)verticalPushViewController:(UIViewController *)controller
{
    [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
    CATransition* transition = [CATransition animation];
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    transition.duration = 0.3;
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromTop;
    [self.view.layer addAnimation:transition forKey:kCATransition];
    [self pushViewController:controller animated:NO];
}

- (UIViewController *)verticalPopViewController
{
    [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
    CATransition* transition = [CATransition animation];
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    transition.duration = 0.3;
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromBottom;
    [self.view.layer addAnimation:transition forKey:kCATransition];
    return [self popViewControllerAnimated:NO];
}
-1
votes

The simplest way.

To present

LaunchImageViewController *launchView = [self.storyboard instantiateViewControllerWithIdentifier:@"launchImage"];
[[UIApplication sharedApplication].keyWindow addSubview:launchView.view];

To close. I calling this inside presented(LaunchImageViewController).

[self.view removeFromSuperview];