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

    1. <legend id='pv6JW'><style id='pv6JW'><dir id='pv6JW'><q id='pv6JW'></q></dir></style></legend>
      • <bdo id='pv6JW'></bdo><ul id='pv6JW'></ul>

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

        <tfoot id='pv6JW'></tfoot>

        在哪里添加 topLayoutGuide 约束代码

        Where to add topLayoutGuide constraint code(在哪里添加 topLayoutGuide 约束代码)

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

          <legend id='HlBJK'><style id='HlBJK'><dir id='HlBJK'><q id='HlBJK'></q></dir></style></legend>
          <tfoot id='HlBJK'></tfoot>
            <tbody id='HlBJK'></tbody>

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

                • <i id='HlBJK'><tr id='HlBJK'><dt id='HlBJK'><q id='HlBJK'><span id='HlBJK'><b id='HlBJK'><form id='HlBJK'><ins id='HlBJK'></ins><ul id='HlBJK'></ul><sub id='HlBJK'></sub></form><legend id='HlBJK'></legend><bdo id='HlBJK'><pre id='HlBJK'><center id='HlBJK'></center></pre></bdo></b><th id='HlBJK'></th></span></q></dt></tr></i><div id='HlBJK'><tfoot id='HlBJK'></tfoot><dl id='HlBJK'><fieldset id='HlBJK'></fieldset></dl></div>
                  本文介绍了在哪里添加 topLayoutGuide 约束代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  想了个办法,把下面的代码放到我的子类导航控制器.m文件的viewDidLoad方法中:

                  Figured out a solution, put the following code in the viewDidLoad method of my subclassed navigation controller .m file:

                  - (void)viewDidLoad {
                      [super viewDidLoad];
                      // Do any additional setup after loading the view.
                  
                      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
                          [[self view] setTranslatesAutoresizingMaskIntoConstraints:NO];
                  
                          id topGuide = [self topLayoutGuide];
                          UIView * selfView = [self view];
                          NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (selfView, topGuide);
                          [[[self view] window] addConstraints:
                           [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topGuide]-0-[selfView]"
                                                               options:0
                                                               metrics:nil
                                                                 views:viewsDictionary]
                          ];
                          [[[self view] window] layoutSubviews]; // You must call this method here or the system raises an exception
                      }
                  }
                  

                  原帖

                  Apple 的 doc 没有说清楚我应该把这段代码放在哪里(哪个类,哪个方法)(不知道 self 指的是什么代码):

                  Original Post

                  Apple's doc didn't say it clear that where (which class, which method) should I put this chunk of code (don't know what does self refers to in the code):

                  [button setTranslatesAutoresizingMaskIntoConstraints: NO];
                  id topGuide = myViewController.topLayoutGuide;
                  NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, topGuide);
                  [myViewController.view addConstraints:
                      [NSLayoutConstraint constraintsWithVisualFormat: @"V: [topGuide]-20-[button]"
                                                                   options: 0
                                                                   metrics: nil
                                                                     views: viewsDictionary]
                  self.view layoutSubviews; // You must call this method here or the system raises an exception
                  ];
                  

                  而且我觉得上面这段代码有一些错字,所以我认为应该是这样的:

                  And I feel that the above chunk of code has some typo, so here's what I think it should be:

                  [button setTranslatesAutoresizingMaskIntoConstraints: NO];
                  id topGuide = myViewController.topLayoutGuide;
                  NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, topGuide);
                  [myViewController.view addConstraints:
                      [NSLayoutConstraint constraintsWithVisualFormat: @"V: [topGuide]-20-[button]"
                                                                   options: 0
                                                                   metrics: nil
                                                                     views: viewsDictionary]
                  ];
                  self.view.layoutSubviews; // You must call this method here or the system raises an exception
                  

                  推荐答案

                  在这种情况下,self 可以引用视图控制器.使用此代码,您正在为其视图添加约束,因此它可以在调用 layoutSubviews 时设置子视图来布局子视图.如果您在 viewDidLoad 方法中添加此代码(我建议您在其中添加),您可以将出现的 myViewController 替换为 self

                  In that case, self can refer to a view controller. With this code, your are adding constraint to its view, so it can layout it subviews as you set them when calling layoutSubviews. If you add this code in the viewDidLoad method (and I recommand you to add it there) you can replace occurrences of myViewController by self

                  这篇关于在哪里添加 topLayoutGuide 约束代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员
                • <small id='nvU4P'></small><noframes id='nvU4P'>

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

                          <tfoot id='nvU4P'></tfoot>

                            <tbody id='nvU4P'></tbody>

                          1. <legend id='nvU4P'><style id='nvU4P'><dir id='nvU4P'><q id='nvU4P'></q></dir></style></legend>