簡體   English   中英

ViewController和自動布局旋轉問題

[英]viewcontroller and autolayout rotation issue

嗨,我正在用以下代碼創建自定義viewcontroller層次結構。 但是,我在子視圖中設置的自動布局似乎不起作用。 當我旋轉設備時,子視圖不會拉伸以適合屏幕。

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

[self.mainView addSubview:_postVC.view];

_postVC.view不拉伸是相同的寬度self.mainView旋轉之后。

你需要:

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

在將_postVC.view添加為_postVC.view的子視圖self.mainView

這樣,1.使_postVC.view適應self.mainView ,並2.將_postVC.view配置為在調整self.mainView的大小時垂直和水平地調整大小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM