我有一个有点像你的问题,导航栏会在[transitionContext completeTransition:YES]
被调用后调整大小,基于与 UIWindow 顶部共享边框的导航栏框架的视觉连续性。我的导航栏离顶部很远,所以它自己调整为 44px,而不是正常的“extend-under-the-status-bar”64px。为了解决这个问题,我只是在动画我toViewController
的 alpha 和位置之前完成了过渡。也就是说,一旦一切都被正确定位以进行动画处理,我调用completeTransition:
了让 navigationController 在不可见的情况下进行自我调整。到目前为止,这还没有任何意外的副作用,并且额外的 alpha in, move frame 动画仍然在你之后继续completeTransition
。
这是我animateTransition:
在演示动画师类中的方法,它符合<UIViewControllerAnimatedTransitioning>
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *presentedViewController = self.presenting ? toViewController : fromViewController;
UIView *containerView = [transitionContext containerView];
NSTimeInterval animationDuration = [self transitionDuration:transitionContext];
if (self.presenting) {
containerView.alpha = 0.0;
presentedViewController.view.alpha = 0.0;
[containerView addSubview:presentedViewController.view];
[UIView animateWithDuration:animationDuration delay:0 options:kNilOptions animations:^{
containerView.alpha = 1.0;
} completion:^(BOOL finished) {
presentedViewController.view.frameTop += 20;
//I complete the transition here, while my controller's view is still invisible,
// but everything is in its proper place. This effectively positions everything
// for animation, while also letting the navigation bar resize itself without jarring visuals.
[transitionContext completeTransition:YES];
//But we're not done quite yet...
[UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
presentedViewController.view.frameTop -= 20;
presentedViewController.view.alpha = 1.0;
} completion:nil];
}];
}
if (!self.presenting) {
[UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
presentedViewController.view.alpha = 0.0;
presentedViewController.view.frameTop += 20;
} completion:^(BOOL finished) {
[UIView animateWithDuration:animationDuration delay:0 options:kNilOptions animations:^{
containerView.alpha = 0.0;
} completion:^(BOOL done) {
[transitionContext completeTransition:YES];
}];
}];
}
希望这可以帮助任何发现自己处于我位置的人!