简体   繁体   English

ViewController和自动布局旋转问题

[英]viewcontroller and autolayout rotation issue

Hi I'm creating my custom viewcontroller hierarchy with the following code. 嗨,我正在用以下代码创建自定义viewcontroller层次结构。 However the autolayout I set in the subview does not seems to work. 但是,我在子视图中设置的自动布局似乎不起作用。 When I rotate the device, the subview does not stretch to fit the screen. 当我旋转设备时,子视图不会拉伸以适合屏幕。

_postVC = [[POSTViewController alloc] initWithNibName:@"POSTViewController" bundle:nil];
[self addChildViewController:_postVC];
[_postVC didMoveToParentViewController:self];

[self.mainView addSubview:_postVC.view];

_postVC.view doesn't stretch to be the same width as self.mainView after rotation. _postVC.view不拉伸是相同的宽度self.mainView旋转之后。

you need to: 你需要:

_postVC.view.frame = self.mainView.bounds // 1 _postVC.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight // 2

before adding _postVC.view as a subview of self.mainView . 在将_postVC.view添加为_postVC.view的子视图self.mainView

this way, 1. _postVC.view is made to fit self.mainView , and 2. _postVC.view is configured to resize both vertically and horizontally when self.mainView is resized. 这样,1.使_postVC.view适应self.mainView ,并2.将_postVC.view配置为在调整self.mainView的大小时垂直和水平地调整大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM