gpt4 book ai didi

swift - UITabBarController View 之间的动画过渡

转载 作者:行者123 更新时间:2023-11-30 11:41:57 25 4
gpt4 key购买 nike

我使用重新定义的 func tabBarController 为 tabbarcontroller 设置自定义类,但当我单击选项卡栏项目时它不会触发。完整项目在这里: 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
}
}

最佳答案

我检查了你的代码,问题是你的实现

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.
}

工作正常

关于swift - UITabBarController View 之间的动画过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49214227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com