Skip to content

Latest commit

 

History

History
33 lines (29 loc) · 859 Bytes

Handling_ChildViewController.md

File metadata and controls

33 lines (29 loc) · 859 Bytes

Handling ChildViewController

Add to parent

private func presentPreview(with videoURL: URL) {
        previewVC = VideoPlayerViewController(videoURL: videoURL)
        guard let previewVC = previewVC else {
            return
        }

        addChild(previewVC)
        view.addSubview(previewVC.view)
        previewVC.view.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.height.equalTo(view.snp.width)
        }
    }

Remove from parent

private func removePreview() {
        if self.children.count > 0 {
            let viewcontrollers: [UIViewController] = self.children
            for vc in viewcontrollers {
                vc.willMove(toParent: nil)
                vc.view.removeFromSuperview()
                vc.removeFromParent()
            }
        }
    }