Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyungpyoda/1ddca999584e9f9bc064fba683198e20 to your computer and use it in GitHub Desktop.
Save kyungpyoda/1ddca999584e9f9bc064fba683198e20 to your computer and use it in GitHub Desktop.
[iOS] Swap window's rootViewController extension with animation flag
//
// UIViewController+setToWindowRootVC.swift
// UtilityModule
//
// Created by 홍경표 on 2021/08/30.
//
import UIKit
public extension UIViewController {
func setToWindowRootVC(animated: Bool = true) {
guard let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) else { return }
window.rootViewController = self
guard animated else { return }
let duration = 0.3
let option: UIView.AnimationOptions = .transitionCrossDissolve
UIView.transition(with: window, duration: duration, options: option, animations: {
}, completion: { completed in
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment