<bdo id='4ZBwE'></bdo><ul id='4ZBwE'></ul>

  • <tfoot id='4ZBwE'></tfoot>

      <legend id='4ZBwE'><style id='4ZBwE'><dir id='4ZBwE'><q id='4ZBwE'></q></dir></style></legend>

      <small id='4ZBwE'></small><noframes id='4ZBwE'>

    1. <i id='4ZBwE'><tr id='4ZBwE'><dt id='4ZBwE'><q id='4ZBwE'><span id='4ZBwE'><b id='4ZBwE'><form id='4ZBwE'><ins id='4ZBwE'></ins><ul id='4ZBwE'></ul><sub id='4ZBwE'></sub></form><legend id='4ZBwE'></legend><bdo id='4ZBwE'><pre id='4ZBwE'><center id='4ZBwE'></center></pre></bdo></b><th id='4ZBwE'></th></span></q></dt></tr></i><div id='4ZBwE'><tfoot id='4ZBwE'></tfoot><dl id='4ZBwE'><fieldset id='4ZBwE'></fieldset></dl></div>

        如何使用 Autolayout 以编程方式将 UIView 居中在现有 UIView 之上?

        时间:2023-09-09

          <legend id='rMNlh'><style id='rMNlh'><dir id='rMNlh'><q id='rMNlh'></q></dir></style></legend>
          • <tfoot id='rMNlh'></tfoot>

            <small id='rMNlh'></small><noframes id='rMNlh'>

            • <bdo id='rMNlh'></bdo><ul id='rMNlh'></ul>

                  <i id='rMNlh'><tr id='rMNlh'><dt id='rMNlh'><q id='rMNlh'><span id='rMNlh'><b id='rMNlh'><form id='rMNlh'><ins id='rMNlh'></ins><ul id='rMNlh'></ul><sub id='rMNlh'></sub></form><legend id='rMNlh'></legend><bdo id='rMNlh'><pre id='rMNlh'><center id='rMNlh'></center></pre></bdo></b><th id='rMNlh'></th></span></q></dt></tr></i><div id='rMNlh'><tfoot id='rMNlh'></tfoot><dl id='rMNlh'><fieldset id='rMNlh'></fieldset></dl></div>
                    <tbody id='rMNlh'></tbody>
                  本文介绍了如何使用 Autolayout 以编程方式将 UIView 居中在现有 UIView 之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果 Foursquare 签入成功,我的 iPhone 应用会在显示的视图之上添加一个视图.

                  In case of a successful Foursquare checkin, my iPhone app shows adds a view on top of the view which is shown.

                  我希望视图以 X 和 Y 为中心,并使用自动布局使其具有确定的宽度和高度,但我不确定以编程方式添加哪些约束.我知道如何在 Storyboard 中执行此操作,但我不确定要输入什么代码才能执行相同的操作,因为稍后会添加此视图以响应应用程序中的成功操作.

                  I want the view to be centered on the X and Y and for it to have a definite width and height using autolayout, but I'm not sure which constraints to add programmatically. I know how to do it in Storyboard, but I'm not sure what exactly to type in code to do the same as this view is added later in response to a successful action in the app.

                  我无法让它正常工作,并且 UIView 有一个用 loadNibNamed: 加载的 nib.

                  I can't get it working properly and the UIView has a nib which it loads with loadNibNamed:.

                  SuccessView *successfulCheckInView = [[SuccessView alloc] initWithFrame:CGRectZero];
                  successfulCheckInView.placeNameLabel.text = properVenue.name;
                  successfulCheckInView.placeAddressLabel.text = properVenue.address;
                  successfulCheckInView.delegate = self;
                  
                  [self.ownerVC.view addSubview:successfulCheckInView];
                  

                  推荐答案

                  试试这个:

                  NSLayoutConstraint *xCenterConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
                  [superview addConstraint:xCenterConstraint];
                  
                  NSLayoutConstraint *yCenterConstraint = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0];
                  [superview addConstraint:yCenterConstraint];
                  

                  为 Swift 更新:

                  Updated for Swift:

                  NSLayoutConstraint(item: view1, attribute: .centerX, relatedBy: .equal, toItem: view2, attribute: .centerX, multiplier: 1, constant: 0).isActive = true
                  
                  NSLayoutConstraint(item: view1, attribute: .centerY, relatedBy: .equal, toItem: view2, attribute: .centerY, multiplier: 1, constant: 0).isActive = true
                  

                  这篇关于如何使用 Autolayout 以编程方式将 UIView 居中在现有 UIView 之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:以编程方式更改小部件布局 下一篇:ios自动布局:以编程方式设置宽度约束

                  相关文章

                    <bdo id='3d1h2'></bdo><ul id='3d1h2'></ul>
                  <legend id='3d1h2'><style id='3d1h2'><dir id='3d1h2'><q id='3d1h2'></q></dir></style></legend>
                1. <small id='3d1h2'></small><noframes id='3d1h2'>

                2. <i id='3d1h2'><tr id='3d1h2'><dt id='3d1h2'><q id='3d1h2'><span id='3d1h2'><b id='3d1h2'><form id='3d1h2'><ins id='3d1h2'></ins><ul id='3d1h2'></ul><sub id='3d1h2'></sub></form><legend id='3d1h2'></legend><bdo id='3d1h2'><pre id='3d1h2'><center id='3d1h2'></center></pre></bdo></b><th id='3d1h2'></th></span></q></dt></tr></i><div id='3d1h2'><tfoot id='3d1h2'></tfoot><dl id='3d1h2'><fieldset id='3d1h2'></fieldset></dl></div>

                  1. <tfoot id='3d1h2'></tfoot>