Objective c 使用自动布局和视觉格式居中子视图

Objective c 使用自动布局和视觉格式居中子视图,objective-c,macos,nslayoutconstraint,autolayout,Objective C,Macos,Nslayoutconstraint,Autolayout,我正在开发一个应用程序,在UI中,superview中有两个子视图。为了以图形方式组织它们,我使用了自动布局和视觉格式。 我的问题是,如何使两个超级视图水平居中? 到目前为止,我已经: parent addConstraints: [NSLayoutConstraint constraintsWithVisualFormat:@"|[subview1]|" options:NSLayoutFormatDirectionLeadingToTrai

我正在开发一个应用程序,在UI中,superview中有两个子视图。为了以图形方式组织它们,我使用了自动布局和视觉格式。 我的问题是,如何使两个超级视图水平居中? 到目前为止,我已经:

 parent addConstraints:
 [NSLayoutConstraint
  constraintsWithVisualFormat:@"|[subview1]|"
                      options:NSLayoutFormatDirectionLeadingToTrailing
                      metrics:metrics
                        views:views];

      parent addConstraints:
 [NSLayoutConstraint
  constraintsWithVisualFormat:@"|[subview2]|"
                      options:NSLayoutFormatDirectionLeadingToTrailing
                      metrics:metrics
                        views:views];

      parent addConstraints:
 [NSLayoutConstraint
  constraintsWithVisualFormat:@"V:|[subview1][subview2]|"
                      options:NSLayoutFormatDirectionLeadingToTrailing
                      metrics:metrics
                        views:views];
有什么想法吗?
提前感谢

那么您的代码有什么问题吗?子视图没有居中。您知道如何仅居中一个视图吗?如果是这样,则可以将两个子视图放置在容器视图中,并使容器视图居中。