系統(tǒng)的,就是好刀崖。 解耦 性好惊科。系統(tǒng)的 最穩(wěn)定, 感覺亮钦。
老師的 真是 炫耀技巧馆截, 造輪子。 效果還不好蜂莉。 tabBar 之間 切換蜡娶, 閃呀閃的。
老師造的輪子映穗, 提供了 另一種 理解 的 思路窖张, 理解系統(tǒng) 是 怎么實(shí)現(xiàn)的。
MainTabBarViewController
class MainTabBarViewController: UITabBarController {
func createViewControllers(){
let arrayNames = ["HomePageViewController","FindViewController","ChefViewController","FairViewController","ProfileViewController"]
let names = ["首頁","發(fā)現(xiàn)","","訂單","我"]
let imageNames = ["dock_home_unselected",
"dock_shop_unselected",
"custom_tabbar",
"dock_order_unselected",
"dock_self_unselected"]
let selectedImageNames = ["dock_home_selected",
"dock_shop_selected",
"custom_tabbar",
"dock_order_selected",
"dock_self_selected"]
var array = Array<UINavigationController>()
for i in 0..<arrayNames.count{
let controllerName = "deliciousOfCource." + arrayNames[i]
let viewControllerClass = NSClassFromString(controllerName) as! UIViewController.Type
let viewController = viewControllerClass.init()
viewController.tabBarItem.title = names[i]
viewController.tabBarItem.image = UIImage(named: imageNames[i])
viewController.tabBarItem.selectedImage = UIImage(named: selectedImageNames[i])
let navigationViewController = UINavigationController(rootViewController: viewController)
array.append(navigationViewController)
}
self.viewControllers = array
}
override func viewDidLoad() {
super.viewDidLoad()
createViewControllers()
self.tabBar.tintColor = UIColor.redColor()
}
KTCHomeViewController
class KTCHomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let appDelegation = UIApplication.sharedApplication().delegate as! AppDelegate
let control = appDelegation.window?.rootViewController
if control?.isKindOfClass(MainTabBarViewController.self) == true {
let mainTabBarCtrl = control as! MainTabBarViewController
mainTabBarCtrl.tabBar.hidden = false
}
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let appDelegation = UIApplication.sharedApplication().delegate as! AppDelegate
let control = appDelegation.window?.rootViewController
if control?.isKindOfClass(MainTabBarViewController.self) == true {
let mainTabBarCtrl = control as! MainTabBarViewController
mainTabBarCtrl.tabBar.hidden = false
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
let appDelegation = UIApplication.sharedApplication().delegate as! AppDelegate
let control = appDelegation.window?.rootViewController
if control?.isKindOfClass(MainTabBarViewController.self) == true {
let mainTabBarCtrl = control as! MainTabBarViewController
mainTabBarCtrl.tabBar.hidden = true
}
}