I want to add a subviewcontroller in the main viewcontroller, but I just want that covers one section, not all the screen. I want it in the middle of the screen. And also, want to know if I can make this subviewcontroller transparent, so I still can see the image background of my main viewcontroller. Currently, I have my mainviewcontroller and I add another viewcontroller using this way:
MenuAllEntriesViewController *menuAE = [[MenuAllEntriesViewController alloc] init];
[menuAE setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:menuAE animated:YES];
But my subviewcontroller covers all the screen... Thank you
To do this programmatically:
First add an empty UIView to your main view. Also create an IBOutlet from your MainWindowController to the view. This will be the container view of your child view controller. Just set its size and position to where you want to display child view.
Then in your MainWindowController.m you can use the following code to add a child view controller whose view is being displayed in the specified view within your main view:
//keep a strong reference to the view controller
self.otherViewController = [[OtherViewController alloc] init];
[self addChildViewController:otherViewController];
//set the frame
CGFloat width = containerView.frame.size.width;
CGFloat height = containerView.frame.size.height;
self.otherViewController.view.frame = CGRectMake(0, 0, width, height);
[containerView addSubview:self.otherViewController.view];
[self.otherViewController didMoveToParentViewController:self];
If you use Storyboards and target iOS 6, you don't even need to do any programming. In the Storyboard view (formerly called Interface Builder) you can just drop a Container View from the Objects Library to your main view. Interface Builder will automatically create a child view controller but you can also point the containment segue to any other view controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With