【问题标题】:UIViewControllerAnimatedTransitioning with UIStatusBarAnimationUIViewControllerAnimatedTransitioning 与 UIStatusBarAnimation
【发布时间】:2014-07-07 15:26:08
【问题描述】:

我在 ViewController A 中实现了该方法

- (BOOL)prefersStatusBarHidden {
  return NO;
}

我在 ViewController B 中实现了该方法

- (BOOL)prefersStatusBarHidden {
  return YES;
}

- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
  return UIStatusBarAnimationSlide; // when doing hiding animation i want it to slide up
}

我实现了一个符合 viewController 转换的类 T,比如 AtoBTransition,我使用这个 ViewControllerTransition 从 vc(viewcontroller) A 转换到 vc B。when transitioning to vc B i want the status bar to slide up (hide with sliding animation) 但在这种情况下,它似乎没有t 做那个滑动动画。

问题:假设我没有在 T 类中执行 UIStatusBar 相关代码,并且没有在 info plist 中添加值 View controller-based status bar appearance。过渡T 可以根据需要完美运行。

  1. 我确定代码通过断点或记录读取-preferredStatusBarUpdateAnimation,但为什么它没有通过滑动隐藏状态栏动画?当我在模拟器中切换到慢动作时。它似乎不做动画。

  2. 我的理论是它与过渡动画上下文冲突,所以是否可以在 T 的实现中做隐藏 UIStatusBar 的动画作为其过渡方案的一部分?

  3. 是否可以将 UIStatusBar 动画与 ViewControllerAnimationTransition 一起制作?

随意清除一些东西。提前谢谢.. :)

【问题讨论】:

  • 您的自定义视图控制器转换(从 A 到 B)是否正常工作?
  • 是的,先生。它工作正常
  • 你能完全隐藏状态栏吗?我认为这就是您在第 1 个问题中所说的,但我不能 100% 确定。
  • 你在视图控制器B中调用[self setNeedsStatusBarAppearanceUpdate];吗?
  • 是的,先生。但这没有帮助。仍然没有发生状态栏动画

标签: ios objective-c animation uistatusbar


【解决方案1】:

我认为您不能直接使用 iOS 7 的视图控制器转换 API 来执行此操作。

现在,我假设基于此 API 和状态栏 API 的钩子,状态栏本身就是一种动物,无法通过自定义过渡进行动画处理。我认为是这种情况,因为当为您创建 UIViewControllerContextTransitioning transitionContext 时,视图控制器 A 已经添加到它的 containerView 并且因为您负责将视图控制器 B 添加到 containerView (因为您需要转换到它)当你这样做时,所有视图控制器 B 的状态栏操作方法都会被触发。

但是,您可以在动画转换期间为UIApplicationkeyWindow 的帧设置动画所以在实现UIViewControllerAnimatedTransitioning 的类的-animateTransition: 方法中。

[UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

    [UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 0, 320, 568);  // move frame up

} completion:^(BOOL finished) {

    // assuming 
    [UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 20, 320, 568); //move frame down
}];

如果您采用这种方法,您可能需要调整视图控制器 A 中关键窗口的框架,使其位于状态栏下方,并根据需要设置为亮/暗的样式。然后反其道而行之,在视图控制器 B 中获得您想要的效果。它很讨厌,但它可以工作。

【讨论】:

  • 先生,如果我们将视图控制器推送到导航控制器,是否也是同样的情况?它仍然有动画过渡(默认)对吧?
  • 我不确定我是否理解您的问题。
  • 我的意思是用self.navigationController pushViewController将视图推送到navigationController@也有过渡。和上面的情况一样吗?因为即使在没有T 的情况下从A 转换到B 时,我也无法制作隐藏状态栏的动画。在将A 转换为B 时不使用T
猜你喜欢
  • 2014-03-12
  • 1970-01-01
  • 2014-11-26
  • 2014-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多