Objective c Xcode 6自动布局子视图约束

Objective c Xcode 6自动布局子视图约束,objective-c,xcode,ios8,autolayout,nslayoutconstraint,Objective C,Xcode,Ios8,Autolayout,Nslayoutconstraint,这是我的故事板 因此,您可以看到,为了调试,我将主视图背景设置为灰色。在这里面我有一个视图,我称之为“图形视图”,它目前就像一个图表子类UIView的布局指南/容器。我对图形视图进行了约束,使其或多或少居中,并根据设备具有可变的宽度/高度,如助手编辑器中所示: 我使用图形视图的bounds.height和bounds.width初始化图表,但这将是interface builder中的大小,即568x500。 在初始化并配置要添加到图形视图的图表之后,我有以下代码 试图为我的图表子视图提供与“图

这是我的故事板

因此,您可以看到,为了调试,我将主视图背景设置为灰色。在这里面我有一个视图,我称之为“图形视图”,它目前就像一个图表子类UIView的布局指南/容器。我对图形视图进行了约束,使其或多或少居中,并根据设备具有可变的宽度/高度,如助手编辑器中所示:

我使用图形视图的bounds.height和bounds.width初始化图表,但这将是interface builder中的大小,即568x500。 在初始化并配置要添加到图形视图的图表之后,我有以下代码 试图为我的图表子视图提供与“图形视图指南”相同的布局/视觉属性:

lineChart.backgroundColor = [UIColor clearColor];
lineChart.translatesAutoresizingMaskIntoConstraints = NO;

[self.graphView addSubview:lineChart];

NSLayoutConstraint *width =[NSLayoutConstraint
                            constraintWithItem:lineChart
                            attribute:NSLayoutAttributeWidth
                            relatedBy:NSLayoutRelationEqual
                            toItem:self.graphView
                            attribute:NSLayoutAttributeWidth
                            multiplier:1.0
                            constant:1];
NSLayoutConstraint *height =[NSLayoutConstraint
                            constraintWithItem:lineChart
                            attribute:NSLayoutAttributeHeight
                            relatedBy:NSLayoutRelationEqual
                            toItem:self.graphView
                            attribute:NSLayoutAttributeHeight
                            multiplier:1.0
                            constant:1];
NSLayoutConstraint *top = [NSLayoutConstraint
                           constraintWithItem:lineChart
                           attribute:NSLayoutAttributeTop
                           relatedBy:NSLayoutRelationEqual
                           toItem:self.graphView
                           attribute:NSLayoutAttributeTop
                           multiplier:1.0f
                           constant:0.f];
NSLayoutConstraint *leading = [NSLayoutConstraint
                               constraintWithItem:lineChart
                               attribute:NSLayoutAttributeLeading
                               relatedBy:NSLayoutRelationEqual
                               toItem:self.graphView
                               attribute:NSLayoutAttributeLeading
                               multiplier:1.0f
                               constant:0.f];

[self.graphView addConstraint:width];
[self.graphView addConstraint:height];
[self.graphView addConstraint:top];
[self.graphView addConstraint:leading];

[self.graphView layoutIfNeeded];
[lineChart layoutIfNeeded];

[lineChart strokeChart];
在iphone5s和ipadair上的结果如下

我想让图表完全填满它的容器。。在iPad中展开,在5s中收缩。 知道我的代码有什么问题吗

谢谢你的帮助

编辑 分别从iPhone 5s和iPad Air的调试视图层次结构输出。

您是否使用XCode中的新调试器工具检查了视图层次结构?我还没有看到这个新功能,谢谢你的指点。在我的问题中投了一个截图。。看起来视图已剪裁,但底部标签未剪裁。。iPad版本甚至更奇怪