0

I have object that manage custom transition:

    @interface NavigationManager : NSObject <UIViewControllerAnimatedTransitioning>

    -(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext;
    -(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext;

    @property (nonatomic, assign) NSTimeInterval presentationDuration;
    @property (nonatomic, assign) NSTimeInterval dismissalDuration;
    @property (nonatomic, assign) BOOL isPresenting;


    @end

    @interface NavigationManager()

    @property (nonatomic, strong) id<UIViewControllerContextTransitioning> transitionContext;

    @end

    @implementation NavigationManager

    @synthesize presentationDuration, dismissalDuration, isPresenting;

    -(id)init{
        self = [super init];

        if(self){

            self.presentationDuration = 1.0;
            self.dismissalDuration = 0.5;
        }

        return self;
    }

    -(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{

        return self.isPresenting ? self.presentationDuration : self.dismissalDuration;
    }

    -(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{


        self.transitionContext = transitionContext;
        if(self.isPresenting){
            [self executePresentation:transitionContext];
        }
        else{

            [self executeDismiss:transitionContext];
        }

    }

    ...


    @end

And in class that should process implement transitions:

@interface ViewController : UIViewController <UIViewControllerTransitioningDelegate>

@property (nonatomic, strong) NavigationManager navigationManager;

..

@end

@implementation

...

//Here I`m doing navigation to new UIViewController

 - (void)navigateToNewScreen
{
    DetailedNewsController *secVC = [[DetailedNewsController alloc] init];
    secVC.fullDescription = fullDescription;
    secVC.headerImage = a.imageView.image;
    self.transitioningDelegate = self;
    [self.navigationController pushViewController:secVC animated:YES];
}

 - (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
    self.animationController.isPresenting = YES;
    return self.animationController;
}

 - (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
    self.animationController.isPresenting = NO;
    return self.animationManager;
}

@end

Default animation of transitioning is performed. Also navigation controller bar is not displayed after navigation.

UPDATE:

I thing problem in way how I`m creating UINavigationController in AppDelegate:

firstVC = [[ViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:firstVC];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor blackColor];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
voiger
  • 781
  • 9
  • 19
Dimitrio
  • 151
  • 4
  • 12
  • 1
    I've never done a custom transition for push, but shouldn't it be `secVC.transitioningDelegate = self;`? – mbo42 Nov 30 '14 at 15:10
  • Changed to: secVC.transitioningDelegate = self; secVC.modalPresentationStyle = UIModalPresentationCustom; [self presentViewController:secVC animated:YES completion:nil]; And it works. But navigationBar is hidden – Dimitrio Nov 30 '14 at 15:30

1 Answers1

1

I'll make an answer with the new information you have provided. The reason I make it an answer is that I just don't want to give you some copy paste code, but to try to give a brief explanation behind it. If I understand correctly, you now want to present a ViewController with a custom transition.

So you got the custom transition working by changing your code to this:

secVC.transitioningDelegate = self; 
secVC.modalPresentationStyle = UIModalPresentationCustom; 
[self presentViewController:secVC animated:YES completion:nil];

Since we got that up and running, what's currently missing is the NavigationBar of the ViewController you want to show. Since you're presenting a ViewController, it won't be contained within the existing NavigationController stack in which the the ViewController you're presenting is within.

Therefore, you need to wrap your VC you want to present within a UINavigationController.

[self presentViewController:[[UINavigationController alloc] initWithRootViewController:secVC] animated:YES completion:nil];
mbo42
  • 759
  • 6
  • 17
  • Thanks, I`ve tried to wrap. But in this case custom animation is not appeared and navigation bar does not have back button. I suppose viewController should be added to stack as child not root – Dimitrio Nov 30 '14 at 19:00
  • I thought you wanted to do a present instead? In which case a back button won't be automatically added to the NavigationBar since it's not being added to any navigation controller stack – mbo42 Nov 30 '14 at 19:04
  • I want to have also ability to return to root controller – Dimitrio Nov 30 '14 at 19:08
  • Okay, sorry for my misunderstanding. So when you changed to `secVC.transitioningDelegate = self;` and called `[self.navigationController pushViewController:secVC animated:YES];` the current problem you have is that secVC's NavigationBar is hidden? – mbo42 Nov 30 '14 at 19:14
  • I use presetViewController: Animation seems done right, but there is not ability to close modal view OR back to root view. Because pushViewController starts default navigation animation – Dimitrio Nov 30 '14 at 19:16
  • So you can add a UIBarButtonItem to the NavigationBar and add a selector for it where you call dismissViewController – mbo42 Nov 30 '14 at 19:29
  • After dismiss animation view is disappearing – Dimitrio Dec 04 '14 at 18:11
  • That sounds like a problem in your custom animation class. Are you adding the fromViewController's view to the container view in the present animation? – mbo42 Dec 04 '14 at 20:37
  • I used solution form: http://stackoverflow.com/questions/25588617/ios-8-screen-blank-after-dismissing-view-controller-with-custom-presentation – Dimitrio Dec 05 '14 at 10:23