2014-10-22 143 views
5

我想使用自定義的UIPresentationController。 對於它,當我想表明新的場景我把這個代碼爲什麼不調用UIViewControllerTransitioningDelegate方法presentationControllerForPresentedViewController?

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

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

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

}]; 

我的過渡經理方法:

#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; 
} 

但該方法presentationControllerForPresentedViewController不來電!

爲什麼?

回答

9

它只會如果你現在使用UIModalPresentationCustom呈現樣式

+0

他使用UIModalPresentationCustom – litso 2015-12-22 23:41:57

+0

@litso確實被調用。我不知道我是如何錯過的,爲什麼我的回答會被接受。作者可能會實現UIViewControllerTransitioningDelegate方法,但不符合此協議。 – Silmaril 2015-12-23 09:15:03

6

modalPresentationStyle代替modalTransitionStyle一個視圖控制器是一個正確的答案:)

+1

哇,我一直在使用自定義轉換一段時間,有時候事情變得很奇怪,我不知道爲什麼。有modalPresentationStyle和modalTransitionStyle ... – 2016-03-09 19:05:02