【发布时间】:2015-01-13 10:57:47
【问题描述】:
正如您在屏幕截图中看到的,这里是灰色的UIView,我将其用作容器。在代码中,我分配了一个UINavigationController 并将它的视图作为子视图添加到灰色容器视图中。 UINavigationController 有 RootViewController(你可以在左侧看到截断的表格视图 - 它是我的 UINavigationController 的根视图控制器)。
我的问题是如何将所有边固定到超级视图边界。因为现在我只能看到RootViewController 视图的一部分。
在情节提要中,我已将所有约束设置为灰色容器视图和UINavigationController 的RootViewController 视图。如果我通常 PushViewController 而不是添加为子视图,它会显示而不会出现中断问题。
这是我在UIViewController 中的代码,其中包含灰色容器视图:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
KNCouponsViewController *couponsViewControllerByList = [KNInstantiateHelper instantiateViewControllerWithIdentifier:@"KNCouponsViewController"];
self.theNavigationController = [[UINavigationController alloc] initWithRootViewController:couponsViewControllerByList];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.theContainerView addSubview:self.theNavigationController.view];
}
这是灰色容器视图的约束
这里是已经切断表的根视图控制器的视图约束:
似乎一个简单的解决方案是将UINavigationController 视图设置为与灰色容器相同的宽度和高度:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect rect = self.theContainerView.frame;
rect.origin.x = 0;
rect.origin.y = 0;
[self.theNavigationController.view setFrame:rect];
[self.theContainerView addSubview:self.theNavigationController.view];
}
然后它工作正常。但我认为如果我们不只修改一个框架,那么它会起作用吗?
【问题讨论】:
标签: ios xcode6 autolayout ios-autolayout