iOS @protocol UIContentContainer <NSObject>

@protocol UIContentContainer <NSObject>

 

@property (nonatomic, readonly) CGSize preferredContentSize ;//iOS8之后,加入了新的一组协议,UIViewController对这组协议提供了默认的实现,我们自定义ViewConttroller的时候可以重写这些方法来调整视图布局。

 

- (void)preferredContentSizeDidChangeForChildContentContainer:(id <UIContentContainer>)container ;//我们可以使用preferredContentSize来设置我们期望的childViewController的界面的大小

 

- (void)systemLayoutFittingSizeDidChangeForChildContentContainer:(id <UIContentContainer>)container;//我们可以使用preferredContentSize来设置我们期望的childViewController的界面的大小

 

 

- (CGSize)sizeForChildContentContainer:(id <UIContentContainer>)container withParentContainerSize:(CGSize)parentSize);//.同上,依旧因为iOS8上size class概念的提出,UIViewConteroller支持了UIConntentContainer这样一组新的协议,重写这些方法可以调整视图布局,一个容器viewController可以使用这个方法设置childViewController的size,当容器viewControllerViewWillTransitionTosize:withTransitionCoordinator:被调用时(我们重写这个方法时要调用super),sizeForChildContentContainer方法将被调用。然后我们可以把需要设置desire发送给childViewController。当我们设置的这个size和当前childViewController的size一样,那么childViewController的viewWillTransitionToSize方法将不会被调用。sizeForChildContentContainer默认的实现是返回parentSize

 

/* 

 This method is called when the view controller's view's size is changed by its parent (i.e. for the root view controller when its window rotates or is resized). 

 

 If you override this method, you should either call super to propagate the change to children or manually forward the change to children.

 */

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);

 

/* 

 This method is called when the view controller's trait collection is changed by its parent.

 

 If you override this method, you should either call super to propagate the change to children or manually forward the change to children.

 */

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);

 

@end

posted on 2017-03-15 11:50  开花结果乐园  阅读(431)  评论(0编辑  收藏  举报

导航