title: Custom animated transition not working when using rootview
body: <p>I am trying to create a custom transition, similar to the one that is on the App Store. I used these tutorials:</p>
  <ul>
  <li><a href="https://eric-dockery283.medium.com/custom-view-transitions-like-the-new-app-store-a2a1181229b6" rel="nofollow noreferrer">https://eric-dockery283.medium.com/custom-view-transitions-like-the-new-app-store-a2a1181229b6</a></li>
  <li><a href="https://www.raywenderlich.com/2925473-ios-animation-tutorial-custom-view-controller-presentation-transitions" rel="nofollow noreferrer">https://www.raywenderlich.com/2925473-ios-animation-tutorial-custom-view-controller-presentation-transitions</a></li>
  </ul>
  <p>I have also been experimenting with using the load view to have the root view to create the view, similar to what is used in the answer used here: <a href="https://stackoverflow.com/questions/61112180/does-loadview-get-called-even-if-we-dont-override-it-in-viewcontroller-like-the">does loadView get called even if we don&#39;t override it in viewcontroller like the other ViewController lifecycle methods?</a></p>
  <p>now what I am doing is that I am using a collectionview, which I want to keep, and when an item is pressed it animate transitions to a new view controller with a larger image, simple.</p>
  <p>the problem is that when I combine it with using the loadView with view = rootView() it did not work in some scenarios.</p>
  <p>For example:</p>
  <p>when I use the modalPresentationStyle = .fullScreen, when I press an item in the collection view the screen just goes black, and then when I press the view hierarchy it shows this:</p>
  <p><a href="https://i.stack.imgur.com/iexyd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iexyd.png" alt="enter image description here" /></a></p>
  <p>when I remove the modalPresentationStyle = .fullScreen it does animate but it is the popover transition, which I do not want.</p>
  <p><a href="https://i.stack.imgur.com/t2IdV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t2IdV.png" alt="enter image description here" /></a></p>
  <p>What I want is to have a full screen transition that is animated.</p>
  <p>here is the view controller:</p>
  <pre><code>class ViewController: UIViewController {
  
    let data = createData()
  
    var transition = PopAnimator()
  
    var rootView = MainView()
  
    private let collectionView: UICollectionView = {
        let viewLayout = UICollectionViewFlowLayout()
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: viewLayout)
        collectionView.backgroundColor = .white
        return collectionView
    }()
  
    private enum LayoutConstant {
         static let spacing: CGFloat = 16.0
         static let itemHeight: CGFloat = 200.0
     }
  
    override func loadView() {
      view = rootView
      rootView.collectionView.delegate = self
      rootView.collectionView.dataSource = self
    }
  }
  
  class MainView: UIView {
  
    let collectionView: UICollectionView = {
        let viewLayout = UICollectionViewFlowLayout()
        let collectionView = UICollectionView(frame: .zero, collectionViewLayout: viewLayout)
        collectionView.backgroundColor = .white
        return collectionView
    }()
  
    init() {
      super.init(frame: .zero)
      setupLayouts()
    }
  
    private func setupLayouts() {
      backgroundColor = .white
      addSubview(collectionView)
  
      collectionView.register(CollectionViewCell.self, forCellWithReuseIdentifier: CollectionViewCell.identifier)
      collectionView.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            collectionView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
            collectionView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor),
            collectionView.leftAnchor.constraint(equalTo: safeAreaLayoutGuide.leftAnchor),
            collectionView.rightAnchor.constraint(equalTo: safeAreaLayoutGuide.rightAnchor)
        ])
    }
  
    required init?(coder: NSCoder) {
      fatalError(&quot;init(coder:) has not been implemented&quot;)
    }
  
  }
  
  extension ViewController: UICollectionViewDataSource {
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return data.count
        }
  
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CollectionViewCell.identifier, for: indexPath) as! CollectionViewCell
  
          cell.dogImg.image = UIImage(named: data[indexPath.row].image)
            return cell
        }
  
    }
  
    extension ViewController: UICollectionViewDelegate {
  
      func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let selected = data[indexPath.row]
        let vc = OtherViewController()
        vc.transitioningDelegate = self
  //      vc.modalPresentationStyle = .fullScreen
  
  
        vc.data = selected
        self.present(vc, animated: true)
        print(selected)
      }
    }
  
  
  extension ViewController: UICollectionViewDelegateFlowLayout {
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
  
          let width = itemWidth(for: view.frame.width, spacing: LayoutConstant.spacing)
  
          return CGSize(width: width, height: LayoutConstant.itemHeight)
      }
  
      func itemWidth(for width: CGFloat, spacing: CGFloat) -&gt; CGFloat {
          let itemsInRow: CGFloat = 2
  
          let totalSpacing: CGFloat = 2 * spacing + (itemsInRow - 1) * spacing
          let finalWidth = (width - totalSpacing) / itemsInRow
  
          return floor(finalWidth)
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -&gt; UIEdgeInsets {
          return UIEdgeInsets(top: LayoutConstant.spacing, left: LayoutConstant.spacing, bottom: LayoutConstant.spacing, right: LayoutConstant.spacing)
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {
          return LayoutConstant.spacing
      }
  
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -&gt; CGFloat {
          return LayoutConstant.spacing
      }
  }
  
  extension ViewController: UIViewControllerTransitioningDelegate {
  
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -&gt; UIViewControllerAnimatedTransitioning? {
      guard let selectedIndexPathCell = self.collectionView.indexPathsForSelectedItems?.first,
            let selectedItem = self.collectionView.cellForItem(at: selectedIndexPathCell) as? CollectionViewCell
      else { return nil }
  
      guard let originFrame = selectedItem.superview?.convert(selectedItem.frame, to: nil) else {
        return transition
      }
  
      transition.originFrame = originFrame
      transition.presenting = true
  
      return transition
    }
  
    func animationController(forDismissed dismissed: UIViewController) -&gt; UIViewControllerAnimatedTransitioning? {
      transition.presenting = false
      return transition
    }
  }
  </code></pre>
  <p>this is the other view that is presented to.</p>
  <pre><code>class OtherViewController: UIViewController, UIViewControllerTransitioningDelegate {
  
    var data: DogArr?
  
    var rootView = testView1()
  
      override func viewDidLoad() {
          super.viewDidLoad()
        self.view.backgroundColor = .systemBackground
      }
  
    override func loadView() {
      view = rootView
      //rootView.inputViewController?.transitioningDelegate = self
      rootView.carImg.image = UIImage(named: data?.image ?? &quot;&quot;)
      rootView.dismissBtn.addTarget(self, action: #selector(dismissingBtn), for: .touchUpInside)
    }
  
    @objc func dismissingBtn() {
      self.dismiss(animated: true)
    }
  }
  
  class testView1: UIView {
    var carImg: UIImageView = {
      let img = UIImageView()
      img.contentMode = .scaleAspectFit
      img.translatesAutoresizingMaskIntoConstraints = false
      return img
    }()
  
    var dismissBtn: UIButton = {
      let btn = UIButton()
      btn.translatesAutoresizingMaskIntoConstraints = false
      btn.setTitle(&quot;Done&quot;, for: .normal)
      btn.titleLabel?.font = UIFont.systemFont(ofSize: 25)
      btn.titleLabel?.textAlignment = .center
      btn.setTitleColor(.label, for: .normal)
      btn.contentMode = .scaleAspectFill
      return btn
    }()
  
    init() {
      super.init(frame: .zero)
      self.addSubview(carImg)
      self.addSubview(dismissBtn)
      carImg.translatesAutoresizingMaskIntoConstraints = false
      self.backgroundColor = .systemBackground
  
      NSLayoutConstraint.activate([
        carImg.topAnchor.constraint(equalTo: self.topAnchor),
        carImg.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.5),
        carImg.widthAnchor.constraint(equalTo: carImg.heightAnchor),
  
        dismissBtn.topAnchor.constraint(equalTo: self.carImg.bottomAnchor, constant: 20),
        dismissBtn.centerXAnchor.constraint(equalTo: self.dismissBtn.centerXAnchor),
        dismissBtn.widthAnchor.constraint(equalToConstant: 150),
        dismissBtn.heightAnchor.constraint(equalToConstant: 75)
      ])
    }
  
    required init?(coder: NSCoder) {
      fatalError(&quot;init(coder:) has not been implemented&quot;)
    }
  }
  </code></pre>
  <p>I noticed that when I remove the root view and just created everything in the view controller, it seems to work, the thing is that this is just a test for now. The root view in a future project may be very large so I think keeping to a rootview may be a good idea. If there are any other methods similar, please share.</p>
  <p>If there is anything I can answer please ask,
  Thank you</p>