【发布时间】:2014-08-09 09:53:33
【问题描述】:
我有一个带有子视图的 testViewController。自动布局已关闭。在 InterfaceBuilder 中,我设置了 Autosizing 属性。
我从我的 MatchViewContoller 中调用这个 viewController:
-(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 方法添加时调整大小不起作用吗?
【问题讨论】:
-
我不确定,但试试这个,
[self.testViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin];可能对你有帮助 -
在添加语句后尝试添加[self.view setNeedsLayout]
标签: ios objective-c resize addsubview