123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import UIKit
- public extension UIViewController {
- func addFullScreen(childViewController child: UIViewController) {
- guard child.parent == nil else { return }
-
- addChild(child)
- view.addSubview(child.view)
- child.view.frame = view.bounds
- if #available(iOS 12, *) {
- child.view.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint.activate([
- child.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
- child.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
- child.view.topAnchor.constraint(equalTo: view.topAnchor),
- child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
- ].compactMap {$0})
- }
-
- child.didMove(toParent: self)
- }
-
- func remove(childViewController child: UIViewController) {
- guard child.parent != nil else { return }
-
- child.willMove(toParent: nil)
- child.view.removeFromSuperview()
- child.removeFromParent()
- }
-
- func removeFromParentAndView() {
- view.removeFromSuperview()
- removeFromParent()
- }
- }
|