5

I want use custom UIPresentationController. For it when I want show new scene I call this code

UIViewController *cv = [[...]];

cv.transitionManager=[[MyTransition alloc] init];
cv.transitioningDelegate=actionSheet.transitionManager;
cv.modalTransitionStyle = UIModalPresentationCustom;

[self presentViewController:cv animated:YES completion:^{

}];

my transition manager has methods:

#pragma mark - UIViewControllerTransitioningDelegate

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

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    return self;
}

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator{
    return  nil;
}

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator{
    return self;
}


- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source {
    MyPresentationController *presentationController = [[MyPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
    return presentationController;
}

but the method presentationControllerForPresentedViewController doesn't call!

Why?

Vit
  • 936
  • 1
  • 10
  • 20

2 Answers2

10

It will be called only if your present a view controller using the UIModalPresentationCustom presentation style

Silmaril
  • 4,241
  • 20
  • 22
  • he is using UIModalPresentationCustom – litso Dec 22 '15 at 23:41
  • @litso indeed. I don't know how I missed that and why my answer wast accepted then. It is possible that author implemented UIViewControllerTransitioningDelegate methods, but did not conformed to this protocol. – Silmaril Dec 23 '15 at 09:15
9

modalPresentationStyle instead of modalTransitionStyle is a correct answer :)

Michal Zaborowski
  • 5,039
  • 36
  • 35
  • 1
    Wow, I have been working with custom transitions for a while and sometimes things got weird and I did not know why. There are modalPresentationStyle and modalTransitionStyle ... – Jakub Truhlář Mar 09 '16 at 19:05
  • 1
    May god bless you and your family for helping me find this stupid mistake. – shannoga May 14 '18 at 12:07