我使用重新定义的func tabBarController为tabbarcontroller设置自定义类,但是当我单击tabbar项时它不会触发。 完整项目在这里: https://drive.google.com/open?id=1vKmruj6yzCHv6bxw6tiRcftqN-UuAp4i
import UIKit
class UITabBarControllerAnimated: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self as? UITabBarControllerDelegate
print("start")
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if selectedViewController == nil || viewController == selectedViewController {
print("nop")
return false
}
let fromView = selectedViewController!.view
let toView = viewController.view
UIView.transition(from: fromView!, to: toView!, duration: 0.8, options: [.transitionCrossDissolve], completion: nil)
print( "animation go")
return true
}
}
答案 0 :(得分:0)
我检查了你的代码是否实现了问题
self.delegate = self as? UITabBarControllerDelegate
它无法使UITabBarController符合UITabBarControllerDelegate, 请做一些改变
class UITabBarControllerAnimated: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
print("start")
// Do any additional setup after loading the view.
}
它工作正常