【问题标题】:Navigation Bar jumping when presenting view controller via UIPresentationController subclass通过 UIPresentationController 子类呈现视图控制器时导航栏跳转
【发布时间】:2015-03-18 13:44:17
【问题描述】:
【问题讨论】:
标签:
ios
objective-c
uinavigationcontroller
uipresentationcontroller
【解决方案2】:
我遇到了一个有点像你的问题,在调用[transitionContext completeTransition:YES] 之后,导航栏会根据与 UIWindow 顶部共享边框的导航栏框架的视觉连续性来调整大小。我的导航栏离顶部很远,所以它自己调整为 44px,而不是正常的“extend-under-the-status-bar”64px。为了解决这个问题,我只是在为toViewController 的 alpha 和位置设置动画之前完成了过渡。也就是说,一旦一切都被正确定位以进行动画处理,我调用completeTransition: 让navigationController 在不可见的情况下进行自我调整。到目前为止,这还没有产生任何意外的副作用,并且在您 completeTransition 之后,额外的 alpha in, move frame 动画仍然继续。
这是我的演示动画师类中的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];
}];
}];
}
希望这可以帮助任何发现自己处于我位置的人!