HeroTransitions / Hero

Elegant transition library for iOS & tvOS
https://HeroTransitions.github.io/Hero/
MIT License
22k stars 1.72k forks source link

在tabbar控制器嵌套的navigation控制器中push进子页面,tabbar的显示/隐藏没有任何动画 #758

Open Zions-Jen opened 1 year ago

Zions-Jen commented 1 year ago

这个问题被提到过多次,但我没有找到解决方案和任何有用的回答,那些问题就被关闭了,所以我再提一次!

我在navigation控制器上启用了hero,在子页面中的所有hero动画效果都正常。

但navigation控制器是嵌入在tabbar控制器中的,当我push到子页面的时候,我需要隐藏tabbar,hidesBottomBarWhenPushed 已设置为true。

但tabbar没有任何动画效果,依然显示,当push完成时,tabbar会突然消失。

pop也一样,在操作完成之前,tabbar仍然不可见,pop完成后,tabbar会突然出现。

我的问题: 我如何在push的同时添加一个动画,让tabbar与系统原本的动画一样消失和显示?

如果做不到,就直接告诉我,让我死了用hero的这个心吧

hochente commented 1 year ago

` let ctrl = UIViewController() ctrl.hidesBottomBarWhenPushed = true self.tabBarController?.tabBar.isHidden = true // <--- 不完美,但勉強可以接受 self.navigationController?.hero.isEnabled = true self.navigationController?.hero.navigationAnimationType = .fade self.navigationController?.pushViewController(ctrl, animated: true)

`

wwdc14yh commented 4 months ago
extension UITabBar {
  open override func action(for layer: CALayer, forKey event: String) -> CAAction? {
    guard event == "position" else { return super.action(for: layer, forKey: event) }
    func genTransition() -> CATransition {
      let transition = CATransition()
      transition.duration = 0.3
      transition.type = .push
      return transition
    }

    if layer.position.x < 0 {
      return genTransition().then {
        $0.subtype = .fromTop
      }
    } else if layer.position.x > 0 && layer.position.y > layer.bounds.size.height && layer.position.y < screenSize.height {
      let fade = CATransition()
      fade.type = .fade
      return fade
    } else {
      return nil
    }
  }

}

这个应该能解决你的问题