Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGAffineTransform translation doesn't work on tabbar after update to Xcode 11

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
    }
like image 281
Thomas Avatar asked Nov 16 '22 23:11

Thomas


1 Answers

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.

like image 65
mtm19 Avatar answered Dec 09 '22 23:12

mtm19