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

    1. <tfoot id='z6JaL'></tfoot>

    2. <legend id='z6JaL'><style id='z6JaL'><dir id='z6JaL'><q id='z6JaL'></q></dir></style></legend>
        <bdo id='z6JaL'></bdo><ul id='z6JaL'></ul>
        <i id='z6JaL'><tr id='z6JaL'><dt id='z6JaL'><q id='z6JaL'><span id='z6JaL'><b id='z6JaL'><form id='z6JaL'><ins id='z6JaL'></ins><ul id='z6JaL'></ul><sub id='z6JaL'></sub></form><legend id='z6JaL'></legend><bdo id='z6JaL'><pre id='z6JaL'><center id='z6JaL'></center></pre></bdo></b><th id='z6JaL'></th></span></q></dt></tr></i><div id='z6JaL'><tfoot id='z6JaL'></tfoot><dl id='z6JaL'><fieldset id='z6JaL'></fieldset></dl></div>
      1. UIStoryboard 如何以编程方式替换约束?

        时间:2023-09-11

          <tfoot id='U0vlG'></tfoot>

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

            • <bdo id='U0vlG'></bdo><ul id='U0vlG'></ul>
            • <legend id='U0vlG'><style id='U0vlG'><dir id='U0vlG'><q id='U0vlG'></q></dir></style></legend>
              <i id='U0vlG'><tr id='U0vlG'><dt id='U0vlG'><q id='U0vlG'><span id='U0vlG'><b id='U0vlG'><form id='U0vlG'><ins id='U0vlG'></ins><ul id='U0vlG'></ul><sub id='U0vlG'></sub></form><legend id='U0vlG'></legend><bdo id='U0vlG'><pre id='U0vlG'><center id='U0vlG'></center></pre></bdo></b><th id='U0vlG'></th></span></q></dt></tr></i><div id='U0vlG'><tfoot id='U0vlG'></tfoot><dl id='U0vlG'><fieldset id='U0vlG'></fieldset></dl></div>

                <tbody id='U0vlG'></tbody>
                  本文介绍了UIStoryboard 如何以编程方式替换约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在情节提要中布置了一个视图控制器,并启用了自动布局,我正在寻找一种方法来更改约束以允许我的视图旋转为横向并重新排列屏幕上的按钮.当我尝试下面的代码时,我收到大约两打无法满足约束,打破约束......"的消息,我无法真正解码.

                  I have a view controller laid out in a storyboard with autolayout enabled and am looking for a way to change constraints to allow for my view to rotate into landscape and rearrange buttons on the screen. When I try the code below, I get about two dozen "unable to satisfy constraints, breaking constraint..." messages that I cannot really decode.

                  有没有办法用我以编程方式指定的约束动态替换情节提要中的约束?我想完全覆盖我在情节提要中定义的按钮布局.

                  Is there a way to dynamically replace constraints from a storyboard with constraints that I specify programmatically? I want to completely override the layout of the buttons that I defined in a storyboard.

                  -(void)updateViewConstraints
                  {
                      [super updateViewConstraints];
                  
                      self.loginButton.translatesAutoresizingMaskIntoConstraints = NO;
                      self.getStartedButton.translatesAutoresizingMaskIntoConstraints = NO;
                      self.takeTourButton.translatesAutoresizingMaskIntoConstraints = NO;
                  
                  
                  
                      [self.loginButton removeConstraints:self.loginButton.constraints];
                      [self.getStartedButton removeConstraints:self.getStartedButton.constraints];
                      [self.takeTourButton removeConstraints:self.takeTourButton.constraints];
                  
                  
                      one = self.loginButton;
                      two = self.getStartedButton;
                      three = self.takeTourButton;
                  
                  
                      NSDictionary *metrics = @{@"height":@50.0,@"width":@100.0,@"leftSpacing":@110.0};
                      NSDictionary *views = NSDictionaryOfVariableBindings(one,two,three);
                  
                      [self.view removeConstraints:activeTestLabelConstraints];
                      [activeTestLabelConstraints removeAllObjects];
                  
                      if(isRotatingToLandscape)
                      {
                  
                          [self registerConstraintsWithVisualFormat:@"|-[one(two)]-[two(three)]-[three]-|" options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom metrics:metrics views:views];
                          [self registerConstraintsWithVisualFormat:@"V:[one(height)]-|" options:0 metrics:metrics views:views];
                  
                      }else
                      {
                  
                          [self registerConstraintsWithVisualFormat:@"|-leftSpacing-[one(width)]" options:0 metrics:metrics views:views];
                          [self registerConstraintsWithVisualFormat:@"[two(width)]" options:0 metrics:metrics views:views];
                          [self registerConstraintsWithVisualFormat:@"[three(width)]" options:0 metrics:metrics views:views];
                          [self registerConstraintsWithVisualFormat:@"V:[one(height)]-[two(75)]-[three(100)]-|" options:NSLayoutFormatAlignAllCenterX metrics:metrics views:views];
                      }
                  
                  
                  }
                  

                  更新了 Rob 的答案,这是我使用的移除约束的方法

                  Updated with Rob's answer, here's the method to remove constraints that I use

                  -(void)removeConstraintForView:(UIView*)viewToModify
                  {
                  
                      UIView* temp = viewToModify;
                      [temp removeFromSuperview];
                      [self.view addSubview:temp];
                  
                  }
                  

                  推荐答案

                  听起来您只想删除视图上的所有约束.由于视图上的约束通常由视图的祖先持有,因此如何轻松删除所有约束并不明显.但其实很简单.

                  It sounds like you want to just remove all the constraints on a view. Since constraints on a view are often held by an ancestor of the view, it's not obvious how to remove all of the constraints easily. But it is actually pretty easy.

                  从视图层次结构中移除一个视图会移除该视图与其外部的其他视图之间的任何约束.因此,只需从其父视图中删除您的视图,然后将其添加回来:

                  Removing a view from the view hierarchy removes any constraints betwixt the view and other views outside of it. So just remove your view from its superview and then add it back:

                  // Remove constraints betwixt someView and non-descendants of someView.
                  UIView *superview = someView.superview;
                  [someView removeFromSuperview];
                  [superview addSubview:someView];
                  

                  如果在 someView 及其后代之间存在任何约束,则这些约束可能由 someView 本身持有(但不能由 someView<的任何后代持有/代码>).如果你也想删除这些约束,你可以直接这样做:

                  If there are any constraints betwixt someView and its descendants, those constraints might be held by someView itself (but cannot be held by any descendants of someView). If you want to remove those constraints also, you can do so directly:

                  // Remove any remaining constraints betwixt someView and its descendants.
                  [someView removeConstraints:[someView constraints]];
                  

                  这篇关于UIStoryboard 如何以编程方式替换约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

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

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