0

Before iOS 13 I would use a transition to go from my LoginVC to my TabBarController. How would I accomplish the following for SceneDelegate? This app has only 1 scene/window

@objc func buttonTapped() {

    let transition = CATransition()
    transition.duration = 0.4
    transition.type = CATransitionType.moveIn
    transition.subtype = CATransitionSubtype.fromTop
    transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.default)

    let appDelegate = UIApplication.shared.delegate as? AppDelegate
    appDelegate?.window?.rootViewController?.view.removeFromSuperview()
    appDelegate?.window?.rootViewController?.dismiss(animated: false, completion: nil)
    appDelegate?.window?.layer.add(transition, forKey: kCATransition)
    appDelegate?.window?.rootViewController = //instance of my TabBarController() and selected index
    appDelegate?.window?.isHidden = false
}

2 Answers 2

1
@objc func buttonTapped() {

    let transition = CATransition()
    transition.duration = 0.4
    transition.type = CATransitionType.moveIn
    transition.subtype = CATransitionSubtype.fromTop
    transition.timingFunction = CAMediaTimingFunction(name:CAMediaTimingFunctionName.default)

    if #available(iOS 13, *) {

        UIApplication.shared.windows.first?.rootViewController?.view.removeFromSuperview()
        UIApplication.shared.windows.first?.rootViewController?.dismiss(animated: false, completion: nil)
        UIApplication.shared.windows.first?.layer.add(transition, forKey: kCATransition)
        UIApplication.shared.windows.first?.rootViewController = // instance of my TabBarController() and selected index
        UIApplication.shared.windows.first?.isHidden = false

    } else {

        let appDelegate = UIApplication.shared.delegate as? AppDelegate
        appDelegate?.window?.rootViewController?.view.removeFromSuperview()
        appDelegate?.window?.rootViewController?.dismiss(animated: false, completion: nil)
        appDelegate?.window?.layer.add(transition, forKey: kCATransition)
        appDelegate?.window?.rootViewController = //instance of my TabBarController() and selected index
        appDelegate?.window?.isHidden = false
    }
}
0
   @objc func buttonTapped() {

         let rootVC = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Tabbarrrrr") as! Tabbarrrrr 
         let navigationController = UINavigationController(rootViewController: rootVC)
         UIApplication.shared.windows.first?.rootViewController = navigationController
         UIApplication.shared.windows.first?.makeKeyAndVisible()

        }

you can use that code..

5
  • Im not looking for the delegate function, I want the same code from my question but not with AppDelegate. A button triggers the transition Commented Feb 28, 2020 at 8:17
  • @LanceSamaria ok wait a sec i'll update my code and in your code there is no button code or you didn't tell that code is for button. so wait Commented Feb 28, 2020 at 8:20
  • oh sorry, i added it Commented Feb 28, 2020 at 8:21
  • @LanceSamaria check my new edit it will set the root view controller but not with animation but i'm trying so please wait Commented Feb 28, 2020 at 8:37
  • I figured it out, thanks. Btw you're not supposed to embed a TabBarController inside a NavigationController because they are both container controllers. Apple recommends against that. You also don't have to use .makeKeyAndVisible() because it's already the key window (unless there was a second window that was key) Commented Feb 28, 2020 at 18:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.