How do add a custom transition delay between view controllers while using coordinators?

69 Views Asked by At

Most of the answers I found for transitioning between view controllers had to do with the normal pushViewController. I am using coordinators for my navigation so was wondering how I can add transition between my UITableView controller and the next transition controller:

Below is the code I am using to navigate between view controllers:

The coordinator:

class ItemsCoordinator: ItemsBaseCoordinator {
    
    func passData(i: Int) {
        let vc = Items2ViewController()
        vc.selectedIndex = i
        //resetToRoot(animated: false)
        navigationRootViewController?.pushViewController(vc, animated: false)
    }

First View Controller:

class ItemsViewController: UITableViewController, ItemsBaseCoordinated{
    
    var coordinator: ItemsBaseCoordinator?
    
    init(coordinator: ItemsBaseCoordinator) {
        super.init(nibName: nil, bundle: nil)
        self.coordinator = coordinator
        title = "Items"
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    
    override func viewDidLoad() {
        super.viewDidLoad()  
        tableView.register(ItemCell.self, forCellReuseIdentifier: "MyCell")
       
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      
        coordinator?.passData(i: indexPath.row)
        
        
    }
}

Second view controller:

class Items2ViewController: UIViewController, ItemsBaseCoordinated {

var coordinator: ItemsBaseCoordinator?
    
    var itemList: [ItemInfo] = [ItemInfo(itemName: "HP Ink Cartridge", itemPrice: 50, itemStatus: "Published", itemImage: UIImage(named: "printer.jpeg")!), ItemInfo(itemName: "iPad",itemPrice: 600, itemStatus: "In Progress", itemImage: UIImage(named: "ipad.jpeg")!),ItemInfo(itemName: "Hoodie",itemPrice: 45, itemStatus: "Unpublished", itemImage: UIImage(named: "hoodie.jpeg")!)]
    

var items: ItemInfo!
var selectedIndex = 0

lazy var descriptionLabel: UILabel = {
    
    
    let dl = UILabel()
    let a = itemList[selectedIndex].itemPrice
    let string = NSMutableAttributedString(string: "Item Price:          $\(a)")
        string.setColorForText("Item Price:", with: #colorLiteral(red: 0.411764705882353, green: 0.411764705882353, blue: 0.411764705882353, alpha: 1))
        
    dl.attributedText = string
    dl.translatesAutoresizingMaskIntoConstraints = false
    dl.font = UIFont.systemFont(ofSize: 18)
    return dl
}()

I am passing data between the view controllers using a protocol function, how do I add a transition delay between the screens?

1

There are 1 best solutions below

0
Tom Brooke On

I just had to set animation to true in the pushviewcontroller