If I follow your question, you are asking how to use controller content restriction in code. I would suggest checking Creating custom container controllers in the View Controller Programming Guide, which shows the code for this, including adding a child view controller:
[self addChildViewController:content]; // 1 content.view.frame = [self frameForContentController]; // 2 [self.view addSubview:self.currentClientView]; [content didMoveToParentViewController:self]; // 3
When using child view controllers (at least those that do not occupy the entire screen), it is useful to have a UIView on the parent view controller's view, which defines the boundaries of the child view's controller. This greatly simplifies the set of tasks. The code snippet above assumes that the subview is called frameForContentController .
Or delete one (in this code snippet, content is a UIViewController * that refers to the remote child controller):
[content willMoveToParentViewController:nil]; // 1 [content.view removeFromSuperview]; // 2 [content removeFromParentViewController]; // 3
And if you want to replace the child controller with another child controller:
- (void) cycleFromViewController: (UIViewController*) oldC toViewController: (UIViewController*) newC { [oldC willMoveToParentViewController:nil]; // 1 [self addChildViewController:newC]; newC.view.frame = [self newViewStartFrame]; // 2 CGRect endFrame = [self oldViewEndFrame]; [self transitionFromViewController: oldC toViewController: newC // 3 duration: 0.25 options:0 animations:^{ newC.view.frame = oldC.view.frame; // 4 oldC.view.frame = endFrame; } completion:^(BOOL finished) { [oldC removeFromParentViewController]; // 5 [newC didMoveToParentViewController:self]; }]; }
I also suggest checking out WWDC 2011 - Implementing the UIViewController Containment .
source share