Keine Beschreibung

UIViewControllerExt.swift 1.3KB

    // // UIViewControllerExt.swift // ExtensionKit // // Created by FFIB on 2017/9/13. // Copyright © 2017年 FFIB. All rights reserved. // import UIKit /// MARK: custom methods extension 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() } }