我有一个视图控制器,它在某些操作上呈现另一个覆盖屏幕下半部分的视图控制器。
当我从底部对第二个视图控制器(呈现视图控制器)进行动画处理以覆盖屏幕的下半部分时,我还希望将呈现视图动画到屏幕的上半部分。请参阅下面的代码 -
- (void)animatePresentationWithTransitioningContext:(id<UIViewControllerContextTransitioning>) transitioningContext
{
UIViewController *presentedController = [transitioningContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *presentedControllerView = [transitioningContext viewForKey:UITransitionContextToViewKey];
UIView *containerView = [transitioningContext containerView];
presentedControllerView.frame = [transitioningContext finalFrameForViewController:presentedController];
CGPoint center = presentedControllerView.center;
center.y = containerView.bounds.size.height;
presentedControllerView.center = center;
[containerView addSubview:presentedControllerView];
// This returns nil
UIView *presentingControllerView = [transitioningContext viewForKey:UITransitionContextFromViewKey];
[UIView animateWithDuration:[self transitionDuration:transitioningContext] delay:0.0 usingSpringWithDamping:1.0 initialSpringVelocity:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
CGPoint presentedViewCenter = presentedControllerView.center;
presentedViewCenter.y -= containerView.bounds.size.height/2.0;
presentedControllerView.center = presentedViewCenter;
// This is where I want to move the presenting view controller.
// of course it does not work.
CGPoint presentingViewCenter = presentingControllerView.center;
presentingViewCenter.y -= containerView.bounds.size.height/2.0;
presentingControllerView.center = presentingViewCenter;
} completion:^(BOOL finished) {
[transitioningContext completeTransition:finished];
}];
}
viewForKey:UITransitionContextFromViewKey
回报nil
。_ 我超越了shouldRemovePresentersView
我NO
的习惯UIPresentationController
,但我仍然得到nil
。我正在使用UIModalPresentationCustom
作为我正在呈现的视图的模态呈现样式。
编辑:
我意识到我可以通过覆盖presentationTransitionWillBegin
我的 custom 中的方法来为呈现视图设置动画来实现相同的效果UIPresentationController
。但我想获得有关访问呈现视图控制器的答案。
编辑: 既然我找到了解决方案,请澄清我的问题:(1)这是预期的行为,即presentingViewController 在动画对象中将为零?