Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
593 views
in Technique[技术] by (71.8m points)

uiviewcontroller - embedding viewcontroller or adding viewcontroller's view - swift - programmatically

What's the difference between adding a viewcontroller's view inside another view controller's view and embedding a view controller like this:

 addChildViewController(controller)

 self.view.addSubview(controller.view)
 controller.view.frame = view.bounds
 controller.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

 controller.didMove(toParentViewController: self)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Embedding a view controller (View Controller Containment) has added benefits such as calls being made to viewDidAppear, viewDidDisappear and rotation and resizing events being passed to the view controller to handle. These don't happen when you just add a view directly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...