Created
August 30, 2021 00:41
-
-
Save kyungpyoda/1ddca999584e9f9bc064fba683198e20 to your computer and use it in GitHub Desktop.
[iOS] Swap window's rootViewController extension with animation flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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