我正在尝试使用手势从ViewController(简单文本页面)移至底部带有TabBar的主ViewController。
该手势在我返回原始主屏幕时有效,但是没有TabBar。
在简单的ViewController中,我使用以下代码返回原始的ViewController。
@objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "AboutViewControllerID")
self.present(controller, animated: true, completion: nil)
if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "AboutViewControllerID") as? AboutViewController
{
present(vc, animated: true, completion: nil)
}
default:
break
}
}
}
在带有TabBarController的ViewController中,我尝试了以下几行以使TabBarController重新焕发活力,但没有任何乐趣。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
tabBarController?.tabBar.isHidden = false
NSLog("TabBar true")
}
有什么想法吗?
答案 0 :(得分:1)
首先,如果要返回,请不要使用present,因为它将在堆栈中添加两次相同的VCS,您必须使用unwindSegue / dismiss或使用id加载tabBar本身
self.dismiss(animated: true) {
// use this if it's not directly behind the dismissed VC
let tab = storyboard.instantiateViewController(withIdentifier: "tabBarID") as! UITabBarController
UIApplication.shared.keyWindow?.rootViewController = tab
}