我有一个使用自定义转换的视图控制器,它运行良好。它利用了这样一个事实,即在使用 UIModalPresentationCustom 时,呈现视图控制器不会被删除,而是将新的视图控制器透明地放置在它上面。
但是,当将此与状态恢复结合使用时,将删除呈现视图控制器。似乎因为视图控制器没有动画呈现,所以从不调用自定义转换代码。有没有办法激活自定义转换,即使视图控制器没有动画?
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
// never called if we aren't animating
return self;
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
return self;
}
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 0.25;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if (toViewController == self) {
[transitionContext.containerView addSubview:fromViewController.view];
[transitionContext.containerView addSubview:toViewController.view];
self.maskView.alpha = 0.0f;
self.menuView.frame = CGRectMake(0, self.view.bounds.size.height, self.view.bounds.size.width, 286.0f);
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
fromViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
[self.menuView updateFrame:^(CGRect *frame) {
frame->origin.y = self.view.bounds.size.height - frame->size.height;
}];
self.maskView.alpha = 0.75f;
} completion:^(BOOL finished) {
self.maskView.userInteractionEnabled = YES;
[transitionContext completeTransition:YES];
}];
} else {
[transitionContext.containerView addSubview:toViewController.view];
[transitionContext.containerView addSubview:fromViewController.view];
self.maskView.userInteractionEnabled = NO;
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
[self.menuView updateFrame:^(CGRect *frame) {
frame->origin.y = self.view.bounds.size.height;
}];
self.maskView.alpha = 0.0f;
} completion:^(BOOL b){
[transitionContext completeTransition:YES];
[self.menuView updateFrame:^(CGRect *frame) {
frame->origin.y = self.view.bounds.size.height - frame->size.height;
}];
}];
}
}