Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Zions-Jen opened this issue Apr 7, 2023 · 2 comments

Comments

@Zions-Jen
Copy link

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

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

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

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

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

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

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

@hochente
Copy link

hochente commented Jun 5, 2023

`
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
Copy link

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
    }
  }
  
}

这个应该能解决你的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants