TabbarControllerHideable 0.3

TabbarControllerHideable 0.3

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最新发布2017 年 7 月
SwiftSwift 版本3.0
SPM支持 SPM

Ezequiel Franca 维护。



  • ezefranca

TabbarControllerHideable

带有显示和隐藏选项的嵌入式 UITabbarController

TabbarControllerHideable

要求

  • Xcode 8.0+
  • iOS 8.3+

示例

要运行示例项目,请首先从仓库克隆,然后在 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 文件。