Last active
June 11, 2018 18:42
-
-
Save MaciejGad/9a4d1f65dcf382373911c90c548d2713 to your computer and use it in GitHub Desktop.
Hiding TabBar with animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITabBarController { | |
func set(visible: Bool, animated: Bool, completion: ((Bool)->Void)? = nil ) { | |
guard isVisible() != visible else { | |
completion?(true) | |
return | |
} | |
let offsetY = tabBar.frame.size.height | |
let duration = (animated ? 0.3 : 0.0) | |
let beginTransform:CGAffineTransform | |
let endTransform:CGAffineTransform | |
if visible { | |
beginTransform = CGAffineTransform(translationX: 0, y: offsetY) | |
endTransform = CGAffineTransform.identity | |
} else { | |
beginTransform = CGAffineTransform.identity | |
endTransform = CGAffineTransform(translationX: 0, y: offsetY) | |
} | |
tabBar.transform = beginTransform | |
if visible { | |
tabBar.isHidden = false | |
} | |
UIView.animate(withDuration: duration, animations: { | |
self.tabBar.transform = endTransform | |
}, completion: { compete in | |
completion?(compete) | |
if !visible { | |
self.tabBar.isHidden = true | |
} | |
}) | |
} | |
func isVisible() -> Bool { | |
return !tabBar.isHidden | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does not work as expected. Leaves a gap at the bottom where the TabBar belongs. Tried it in a view with a NavigationBar + TabBar.