// // MainTabBarViewController.swift // dzwww // // Created by Virgil on 2017/11/1. // Copyright © 2017年 Virgil. All rights reserved. // import UIKit class MainTabBarViewController: UITabBarController { var btnCreate: UIButton! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.white } var arrBtnMenus = [UIButton]() ///跳动的按钮,不需要则不调用 func initMenuImageAnimation() { self.tabBar.clipsToBounds = false let viewMain = UIView(frame: CGRect(x: 0, y: 1, width: self.tabBar.frame.width, height: self.tabBar.frame.height - 18)) self.tabBar.addSubview(viewMain) viewMain.backgroundColor = UIColor.white viewMain.clipsToBounds = false let width = viewMain.frame.width / 5 for i in 1 ..< 6 { let btn = UIButton(frame: CGRect(x: width * CGFloat(i - 1), y: 0, width: width, height: viewMain.frame.height)) btn.setImage(UIImage(named: appDelegate.arrIcon[i-1]), for: .normal) btn.setImage(UIImage(named: "\(appDelegate.arrIcon[i-1])_s"), for: .selected) btn.contentVerticalAlignment = .bottom btn.tag = i btn.addTarget(self, action: #selector(btnChangeItem), for: .touchUpInside) viewMain.addSubview(btn) if i == 1 { oldSelectedBtn = btn oldSelectedBtn.isSelected = true } arrBtnMenus.append(btn) } } ///初始化中间的大按钮 func initMenuBigCenterButton() { btnCreate = UIButton(frame: CGRect(x: (ScreenWidth - 52)/2, y: -3, width: 52, height: 52)) btnCreate.backgroundColor = UIColor.clear btnCreate.setBackgroundImage(UIImage(named: "btncreate"), for: .normal) self.tabBar.addSubview(btnCreate) btnCreate.isHidden = false btnCreate.addTarget(self, action: #selector(btnCreateClick), for: .touchUpInside) } @objc func btnCreateClick() { } var oldSelectedBtn: UIButton! @objc func btnChangeItem(btn: UIButton) { if oldSelectedBtn != nil { oldSelectedBtn.isSelected = false } self.selectedIndex = btn.tag - 1 btn.isSelected = true oldSelectedBtn = btn CommonAnimation.popJumpAnimationView(view: btn, repeatCount: 1, duration: 1, values: [0, -20, 0, -8, 0, -4, 0], keyTimes: [0, 0.2, 0.4, 0.6, 0.8, 0.9, 1]) // CommonAnimation.popRotationAnimation(view: btn) } override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { let index = tabBar.items?.index(of: item)! if arrBtnMenus.count > index! { btnChangeItem(btn: arrBtnMenus[index!]) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. } */ }