Ios 未使用addSubview调整子视图的大小
我有一个testViewController,它有一个子视图。自动布局已关闭。在InterfaceBuilder中,我设置了自动调整大小属性 我从我的MatchViewController调用此viewController:Ios 未使用addSubview调整子视图的大小,ios,objective-c,resize,addsubview,Ios,Objective C,Resize,Addsubview,我有一个testViewController,它有一个子视图。自动布局已关闭。在InterfaceBuilder中,我设置了自动调整大小属性 我从我的MatchViewController调用此viewController: -(void)showTutorial { self.testViewController = [[TestViewController alloc] init]; [self.view addSubview:self.testViewController
-(void)showTutorial
{
self.testViewController = [[TestViewController alloc] init];
[self.view addSubview:self.testViewController.view];
}
在testViewController中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.view.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:.6];
}
视图显示正确,但在iPhone 3.5英寸模拟器中打开视图时,子视图的大小没有调整。因此,现在底部不可见
我已经用[self.navigationController-pushViewController:testViewController-animated:NO]试过了代码>然后它就可以正常工作了。。。子视图的子视图已完全调整大小。
但是当我使用[self.view addSubview:self.testViewController.view]时代码>未调整子视图的大小
我已经尝试了在testViewController和MatchViewController上打开和关闭“自动调整子视图大小”的所有组合。。。但什么都不管用
我错过了什么?使用addSubview方法添加testViewController时,调整大小不起作用吗?问题是,您将testViewController的视图添加为子视图,但没有在viewController层次结构中添加控制器,因此不会调用像viewDidLoad这样的生命周期调用
试试这个:
-(void)showTutorial
{
self.testViewController = [[TestViewController alloc] init];
[self addChildViewController:self.testViewController];
[self.testViewController didMoveToParentViewController:self];
[self.view addSubview:self.testViewController.view];
}
我不确定,但尝试一下,[self.testViewController.view setAutoresizingMask:uiviewautoresizingflexiblewhight | UIViewAutoresizingFlexibleWidth | uiviewautoresizingflexibletpmargin | UIViewAutoresizingFlexibleLeftMargin]代码>在添加语句之后添加[self.view setNeedsLayout]是否有助于您的尝试否,这并不能解决问题。我还调试了,在我自己的解决方案中,ViewDidLoad被称为。。。