5

I am trying to update my project to iOS 13. I used to hide the tabbar using a CGAffineTransform translation and it worked like a charm until I updated to Xcode 11 and executed my code on iOS 13.

I have tried recreate a small project with a simple UITabBarController and a simple UIViewController with a button to show/hide my tabbar. (See below).

Even the transformation to identity doesn't works as expected.

Others CGAffineTransform like rotation woks as expected.

@objc fileprivate func showOrHideTabbar() {

        if !hidden {
            print("hiding")
            UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseOut, animations: {
                self.tabBarController?.tabBar.transform = CGAffineTransform(translationX: 0, y: 100)
            })
        } else {
            print("showing")
            UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseOut, animations: {
                self.tabBarController?.tabBar.transform = .identity
            })
        }
        hidden = !hidden
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Thomas
  • 51
  • 1
  • 1
    Personally I have never found using a transform to reliably hide the tabBar. I have found the extension to work for me. https://stackoverflow.com/a/44707169/5508175. It does work on iOS 13 – Andrew Oct 02 '19 at 10:37
  • 2
    Thanks, reading the post helped my find another way to hide it with animation. I now modify the frame to add an offset: let frame = self.tabBarController!.tabBar.frame self.tabBarController!.tabBar.frame = frame.offsetBy(dx: 0, dy: 100) It works like that but I am still trying to understand why CGAffineTransform doesn't work anymore. – Thomas Oct 02 '19 at 10:43
  • I'm experiencing the same issue after updating to Xcode 11, as far as I investigated the issue looks like tabbar frame height is modified when it goes offscreen, but I never heard Apple saying to modify iOS 12 behavior on this topic :/ – Robert Juz Jan 06 '20 at 16:59
  • Same issue for me too, same code working while running in iOS 12, but not working when running in iOS 13. Maybe it is happening because of ios 13 window hierarchy. – Subhajit Halder Mar 05 '20 at 22:36

1 Answers1

2

I know this might be late but it may be helpful for other users looking for this answer. To translate the tab bar to the right/left/top/bottom you would need to change its origin. So, instead of this line:

self.tabBarController?.tabBar.transform = CGAffineTransform(translationX: 0, y: 100)

You should change it to this line:

self.tabBarController?.tabBar.frame.origin.y += 100

Ofcourse, you can change the value 100 to suit your needs, this line will move your tab bar to the bottom, if you want it to move to the top you would need to do this instead:

self.tabBarController?.tabBar.frame.origin.y -= 100

Obviously if you want to change the x position, you would change .y to .x.

Dharman
  • 30,962
  • 25
  • 85
  • 135
mtm19
  • 61
  • 3