Im new in swift and im trying to do some custom think. I have MainViewController
and this controller has bgView
. I set ViewController1
and ViewController2
to MainViewController
in bgView
. But when i set ViewController1
and ViewController2
many times the app starts to freeze
MainViewController
code
@IBOutlet weak var bgView: UIView!
add and remove Controller from bgView
private func add(asChildViewController viewController: UIViewController) {
// Add Child View Controller
addChild(viewController)
// Add Child View as Subview
bgView.addSubview(viewController.view)
// Configure Child View
viewController.view.frame = bgView.bounds
viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Notify Child View Controller
viewController.didMove(toParent: self)
}
private func remove(asChildViewController viewController: UIViewController) {
// Notify Child View Controller
viewController.willMove(toParent: nil)
// Remove Child View From Superview
viewController.view.removeFromSuperview()
// Notify Child View Controller
viewController.removeFromParent()
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…