[英]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.