在iOS中加载NIB后使用自动布局

在iOS中加载NIB后使用自动布局,ios,uiviewcontroller,autolayout,constants,nib,Ios,Uiviewcontroller,Autolayout,Constants,Nib,我有NibVC和NibView,我为不同的设备设置了自动布局 我用代码将NibView加载到NibVC - (id)initWithCoder:(NSCoder *)aDecoder { if ((self = [super initWithCoder:aDecoder])) { self.profileHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"ProfileHeaderView" owner:self options:nil

我有NibVC和NibView,我为不同的设备设置了自动布局

我用代码将NibView加载到NibVC

- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
    self.profileHeaderView = [[[NSBundle mainBundle] loadNibNamed:@"ProfileHeaderView" owner:self options:nil] firstObject];
    self.profileHeaderView.delegate = self;
    [self.view addSubview:self.profileHeaderView];
 }
    return self;    
 }
此外,我还有一些占位符视图,在我不加载此代码之前,它会显示在我的NibVC中

但当我加载这个视图时,它并没有根据约束调整大小。是的,这没关系,因为在initWithCoder的生命周期中没有设置包含

但是我怎样才能加载约束呢

我可以手动设置帧,但我不喜欢

CGFloat scale = rect.size.width / rect.size.height;
CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
CGFloat scaledH = 1/scale * screenW;
rect.size.width = screenW;
rect.size.height = scaledH;
我也试过这篇文章

但我不知道为什么,如果有人能看到我的代码中的这几行,我会非常高兴,它就在那里