测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布最新发布 | 2017 年 7 月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Ezequiel Franca 维护。
带有显示和隐藏选项的嵌入式 UITabbarController
要运行示例项目,请首先从仓库克隆,然后在 Example 目录下运行 pod install
要程序化地开始使用 TabbarControllerHideable,您可以像初始化一个普通的 UITabbarController
一样进行初始化
let firstTab: UIViewController = UIViewController()
let secondTab: UIViewController = UIViewController()
let tabs = NSArray(objects: firstTab, secondTab)
let tabBarController = UITabBarHideableController()
// Set ViewControllers
tabBarController?.setViewControllers(tabs as? [UIViewController], animated: false)
要使用显示/隐藏方法,您的控制器需要实现 UITabbarItemHideable
协议,并且可以通过协议方法之一程序化地获取 tabs 项
func getTabbarItem(coder:NSCoder) -> UITabBarItem?
func getTabbarItem(title: String?, image: UIImage?, tag: Int) -> UITabBarItem
func getTabbarItem(title: String?, image: UIImage?, selectedImage: UIImage?) -> UITabBarItem
func getTabbarItem(tabBarSystemItem systemItem: UITabBarSystemItem, tag: Int) -> UITabBarItem
import UIKit
class FirstViewController: UIViewController, UITabbarItemHideable {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarItem = getTabbarItem(tabBarSystemItem: .featured, tag: 1)
self.view.backgroundColor = UIColor.red
let button = UIButton(frame: CGRect(x: self.view.center.x - 30, y: self.view.center.y - 30, width: 60, height: 60))
button.backgroundColor = UIColor.white
button.addTarget(self, action: #selector(hideTapped), for: .touchUpInside)
self.view.addSubview(button)
}
func hideTapped() {
if !(self.tabBarController as! UITabBarHideableController).isHidded {
(self.tabBarController as! UITabBarHideableController).hideTabBar(animated: true, duration: 0.75)
}
else {
(self.tabBarController as! UITabBarHideableController).showTabBar(animated: true)
}
}
}
class SecondViewController: UIViewController, UITabbarItemHideable {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarItem = getTabbarItem(tabBarSystemItem: .search, tag: 2)
self.view.backgroundColor = UIColor.blue
let button = UIButton(frame: CGRect(x: self.view.center.x - 30, y: self.view.center.y - 30, width: 60, height: 60))
button.backgroundColor = UIColor.white
button.addTarget(self, action: #selector(hideTapped), for: .touchUpInside)
self.view.addSubview(button)
}
func hideTapped() {
if !(self.tabBarController as! UITabBarHideableController).isHidded {
(self.tabBarController as! UITabBarHideableController).hideTabBar(animated: true)
}
else {
(self.tabBarController as! UITabBarHideableController).showTabBar(animated: true, duration: 0.75)
}
}
}
ezefranca,[email protected]
TabbarControllerHideable 遵循 MIT 许可协议。有关更多信息,请参阅 LICENSE 文件。