【问题标题】:iOS 7 Custom Present Transition with UINavigationController带有 UINavigationController 的 iOS 7 自定义当前转换
【发布时间】:2013-11-17 05:06:12
【问题描述】:

我正在使用 iOS 7 自定义过渡来呈现 UINavigationController。 但有一个问题。在动画时,导航栏的大小只有 44 点。然后在完成动画后,导航控制器发现有一个状态栏,所以它为状态栏添加了 20 个点。

我的问题是,是否可以在动画时将导航栏设置为 64 点,所以当它完成动画时它不会再改变了。

请在此处查看更多详细信息Custom View Transitions

这是我的自定义动画代码:

 - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{

    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    CGRect finalFrame = [transitionContext finalFrameForViewController:toViewController];

    UIView *containerView = [transitionContext containerView];

    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    toViewController.view.frame = CGRectOffset(finalFrame, 0, screenBounds.size.height);
    [containerView addSubview:toViewController.view];

    NSTimeInterval duration = [self transitionDuration:transitionContext];

    [UIView animateWithDuration:duration delay:0.0 usingSpringWithDamping:0.6 initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
        toViewController.view.frame = finalFrame;
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
}

更新:有人解决了这个问题。但很hacky。 将 toViewController.view 添加到 containerView 后添加此代码。

if ([toViewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController* navigationController = (UINavigationController*) toViewController;
    UINavigationBar* bar = navigationController.navigationBar;
    CGRect frame = bar.frame;
    bar.frame = CGRectMake(frame.origin.x, frame.origin.y + 20.0f, frame.size.width, frame.size.height);
}

有没有更好的方法?

【问题讨论】:

  • 您的视图控制器是否显示状态栏?你的视图控制器是否显示状态栏?

标签: ios uinavigationcontroller ios7 statusbar transitions


【解决方案1】:

我遇到了同样的问题,并在设置此框架之前解决了将 toViewController 添加到容器的问题。

如下反转行:

[containerView addSubview:toViewController.view];
toViewController.view.frame = CGRectOffset(finalFrame, 0, screenBounds.size.height);

【讨论】:

  • 哇,我搜索并试验了很长时间 - 就像一个魅力!
  • 很棒的发现!谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多