These have been used in an internal project. I think they would be a good addition to RZUtils. I'll throw the code here, and make a PR at some point.
For discussion: Do we like the dependence on the RZ auto layout helpers, or should this do the layout independently?
@interface UIViewController (RZViewControllerContainment)
/**
* Adds a view controller as a child of the receiver, and uses Auto Layout to fill the receiver.
*
* @param childViewController The view controller to add as a child.
*/
- (void)rz_addChildViewController:(UIViewController *)childViewController;
/**
* Adds a view controller as a child of the receiver, and uses Auto Layout to fill a specified subview of the receiver.
*
* @param childViewController The view controller to add as a child.
* @param view The view to fill with the child view controller’s view. Must be a subview of the receiver’s view.
*/
- (void)rz_addChildViewController:(UIViewController *)childViewController toView:(UIView *)view;
/**
* Adds a view controller as a child of the receiver. Provides a way to set your own constraints to define how the child view controller’s view fills the parent view.
*
* @param childViewController The view controller to add as a child.
* @param view The view to act as the superview to the child view controller’s view. Must be a subview of the receiver’s view.
* @param constraintBlock This block will be called synchronously when the child view controller’s view is ready to receive constraints. Use it to configure custom constraints on the child view controller. If you need to access the parent view, use the child view controller’s @c superview property.
*/
- (void)rz_addChildViewController:(UIViewController *)childViewController toView:(UIView *)view constraintBlock:(void(^)(UIView *childViewControllerView))constraintBlock;
/**
* Removes a view controller as a child of the receiver.
*
* @param childViewController The child view controller to remove.
*/
- (void)rz_removeChildViewController:(UIViewController *)childViewController;
@end
These have been used in an internal project. I think they would be a good addition to RZUtils. I'll throw the code here, and make a PR at some point.
For discussion: Do we like the dependence on the RZ auto layout helpers, or should this do the layout independently?