我将UIViewController
添加到了UITabBarControllerDelegate
类型的ViewController中,并扩展为拥有tabBar
如何检测何时单击了import UIKit
class VHomeViewController: UIViewController, UITabBarControllerDelegate {
@IBOutlet weak var menuButton: UIBarButtonItem!
@IBOutlet weak var navigation_header: UINavigationBar!
@IBOutlet weak var tabbar_header: UITabBar!
override func viewDidLoad() {
super.viewDidLoad()
tabbar_header.delegate = self as? UITabBarDelegate
loadDesign()
if revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
}
}
func loadDesign(){
//set background
self.view.backgroundColor = UIColor(patternImage: (UIImage(named: "main_background") ?? nil)!)
//navigation transparent
self.navigation_header.setBackgroundImage(UIImage(), for: .default)
self.navigation_header.shadowImage = UIImage()
self.navigation_header.isTranslucent = true
self.navigation_header.backgroundColor = .clear
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
print("Hello")
}
}
个项目?
viewController代码如下:
{{1}}